Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7435713
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:07:13+00:00 2026-05-29T10:07:13+00:00

In the following code, a Null pointer exception is raised when I try to

  • 0

In the following code, a Null pointer exception is raised when I try to call beginTransaction method. I thought that JBoss would init my transaction… apparently not :\

What am I missing ?

JBoss 5.1.0.GA
JPA 1
JDK 6



import javax.annotation.Resource;
import javax.persistence.EntityManagerFactory;
import javax.persistence.PersistenceUnit;
import javax.transaction.UserTransaction;

public abstract class AbstractDAO {
    @PersistenceUnit(unitName = "miniDS")
    protected static EntityManagerFactory emf;
    @Resource
    protected UserTransaction t;

    public AbstractDAO() {

    }

    protected void beginTransaction() throws Throwable {
        t.begin();
    }

    protected void commitTransaction() throws Throwable {
        t.commit();
    }

    protected void rollbackTransaction() throws Throwable {
        t.rollback();
    }
}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T10:07:14+00:00Added an answer on May 29, 2026 at 10:07 am

    Your AbstractDAO does not seem to be managed. Injection only works in container managed objects. This is not specific to injection of UserTransaction, but injection in general. As result emf is null as well. Java EE specification lists following classes to be able to use injection:

    • Servlet: servlets, servlet filters, event listeners
    • JSP: tag handlers, tag library event listeners
    • JSF: scoped managed beans
    • JAX-WS: service endpoints, handlers
    • EJB: beans, interceptors
    • Managed Beans: managed beans
    • CDI: CDI-style managed beans, decorators
    • Java EE Platform: main class (static), login callback handler

    Possible workaround are to move injection of resources to managed class or use JNDI lookup.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I try in following way but I am getting Null Pointer Exception at iv.setImageBitmap(bm).
Consider the following code: try { int *i = NULL; i[100] = 20; catch
I have a method that looks like this: try { doStuff(); } catch (Exception
The following code prints null once. class MyClass { private static MyClass myClass =
The following code does not run as rootNode is null when retrieved by name
The following code is throwing the error this.element is null. However, the wid_cont is
Given the following code: int *a = NULL; a = calloc(1, sizeof(*a)); printf(%d\n, a);
I have the following unmanaged C++ code: MessageBox( NULL, strMessage, Cool Product, MB_RETRYCANCEL |
In the following code: public class A { public A():this(null){} public A(string b){/*code here*/}
I have the following code but the lon/lat seems to be returning null; package

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.