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 7917721
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T15:14:46+00:00 2026-06-03T15:14:46+00:00

I’m a java beginner. I’m in trouble to configure a persistance unit using JTA

  • 0

I’m a java beginner. I’m in trouble to configure a persistance unit using JTA transactions.
I need to use a PostgreSQL database that is already defined, configured and populated. Using netbeans, i created the persistance.xml and glassfish-resources.xml as fallows:

<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
    <persistence-unit name="WellWatcherPU" transaction-type="JTA">
         <jta-data-source>WellWatcherDB</jta-data-source>
         <exclude-unlisted-classes>false</exclude-unlisted-classes>
         <properties>
             <property name="eclipselink.logging.logger" value="org.eclipse.persistence.logging.DefaultSessionLog"/>
             <property name="eclipselink.logging.level" value="FINE"/>
         </properties>
     </persistence-unit>
</persistence>

and

<resources>
    <jdbc-connection-pool allow-non-component-callers="false" associate-with-thread="false" connection-creation-retry-attempts="0" connection-creation-retry-interval-in-seconds="10" connection-leak-reclaim="false" connection-leak-timeout-in-seconds="0" connection-validation-method="auto-commit" datasource-classname="org.postgresql.ds.PGSimpleDataSource" fail-all-connections="false" idle-timeout-in-seconds="300" is-connection-validation-required="false" is-isolation-level-guaranteed="true" lazy-connection-association="false" lazy-connection-enlistment="false" match-connections="false" max-connection-usage-count="0" max-pool-size="32" max-wait-time-in-millis="60000" name="post-gre-sql_geowellex_geowellexPool" non-transactional-connections="false" pool-resize-quantity="2" res-type="javax.sql.DataSource" statement-timeout-in-seconds="-1" steady-pool-size="8" validate-atmost-once-period-in-seconds="0" wrap-jdbc-objects="false">
        <property name="serverName" value="localhost"/>
        <property name="portNumber" value="5432"/>
        <property name="databaseName" value="DBNAME"/>
        <property name="User" value="USER"/>
        <property name="Password" value="PASSWORD"/>
        <property name="URL" value="jdbc:postgresql://localhost:5432/DBNAME"/>
        <property name="driverClass" value="org.postgresql.Driver"/>
    </jdbc-connection-pool>
    <jdbc-resource enabled="true" jndi-name="WellWatcherDB" object-type="user" pool-name="post-gre-sql_geowellex_geowellexPool"/>
</resources>

And this is how i get the EntityManagerFactory and EntityManager (as used in the netBeans example)

public class EUserDao {

@Resource
private UserTransaction utx = null;
@PersistenceUnit(unitName = "WellWatcherPU")
private EntityManagerFactory emf = null;

public EntityManager getEntityManager() {
    return emf.createEntityManager();  <-------- NullPointerException here
}

public EUser getOne(long userId){
    EntityManager em = getEntityManager();
    try {
        return em.find(EUser.class, userId);
    } finally {
        em.close();
    }
}

EDIT:

And here is my glassfish deploy log:

Informações: [EL Config]: 2012-05-10 12:01:13.534–ServerSession(2017352940)–Connection(1901223982)–Thread(Thread[admin-thread-pool-4848(5),5,grizzly-kernel])–connecting(DatabaseLogin(
platform=>DatabasePlatform
user name=> “”
connector=>JNDIConnector datasource name=>null
))

Informações: [EL Config]: 2012-05-10 12:01:13.534–ServerSession(2017352940)–Connection(1462281761)–Thread(Thread[admin-thread-pool-4848(5),5,grizzly-kernel])–Connected: jdbc:postgresql://localhost:5432/geowellex?loginTimeout=0&prepareThreshold=0
User: geowellex
Database: PostgreSQL Version: 9.1.3
Driver: PostgreSQL Native Driver Version: PostgreSQL 8.3 JDBC3 with SSL (build 603)

Informações: [EL Config]: 2012-05-10 12:01:13.534–ServerSession(2017352940)–Connection(766700859)–Thread(Thread[admin-thread-pool-4848(5),5,grizzly-kernel])–connecting(DatabaseLogin(
platform=>PostgreSQLPlatform
user name=> “”
connector=>JNDIConnector datasource name=>null
))

What’s wrong?

  • 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-06-03T15:14:47+00:00Added an answer on June 3, 2026 at 3:14 pm

    Most likely problem is that your EUserDao is just regular class. Injection works only for container managed classes. Annotations like @PersistenceUnit and @Resource are not processed for normal classes.

    Following types of classes are container managed classes (and in those @PersistenceUnit can be used):

    • 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
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have thousands of HTML files to process using Groovy/Java and I need to
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
I am trying to understand how to use SyndicationItem to display feed which is
I've got a string that has curly quotes in it. I'd like to replace
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I am doing a simple coin flipping experiment for class that involves flipping a

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.