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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:06:42+00:00 2026-05-26T07:06:42+00:00

Noob question here. I’m following this example/tutorial to try and isolate a problem I

  • 0

Noob question here. I’m following this example/tutorial to try and isolate a problem I keep getting on my main project. Problem is, the entityManagerFactory keeps returning null (thus, I get a NullPointerExcept when trying to run the first JUnit test.)

I’m currently on Eclipse Indigo (JavaEE) – JRE7 – Hibernate 3.6.7 and JBoss 7

And here’s my persistence.xml (again, a copipasta taken right from the tutorial)

<persistence>
        <persistence-unit name="examplePersistenceUnit" 
                          transaction-type="RESOURCE_LOCAL">
            <properties>
                <property name="hibernate.show_sql" value="false" />
                <property name="hibernate.format_sql" value="false" />

                <property name="hibernate.connection.driver_class" 
                          value="org.hsqldb.jdbcDriver" />
                <property name="hibernate.connection.url" 
                          value="jdbc:hsqldb:mem:mem:aname" />
                <property name="hibernate.connection.username" value="sa" />

                <property name="hibernate.dialect" 
                          value="org.hibernate.dialect.HSQLDialect" />
                <property name="hibernate.hbm2ddl.auto" value="create" />
            </properties>
        </persistence-unit>
    </persistence>

Things I’ve already tried/found out so far:

  • Seems this problem tends to occur if you try to create a factory
    with a persistence unit that is not listed in the persistence.xml

  • Double-checked that the necessary JARs are included in Eclipse’s
    Build Path Libraries, which Google suggested may be a possible cause
    for a createEntityManagerFactory() call to short-circuit and return
    null (instead of just throwing an exception or logging a message)

  • Might be due to a possible error whilst configuring Hibernate
    connection?

I’ve been hitting this wall for the past couple of weeks, so it goes without saying that any help/general direction tips are MUCH appreciated 😀

  • 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-26T07:06:42+00:00Added an answer on May 26, 2026 at 7:06 am

    Gaston, I have some suggestions/questions for you:

    1 – Is this the code you’re trying to execute?

    package entity;
    
    import javax.persistence.EntityManager;
    import javax.persistence.EntityManagerFactory;
    import javax.persistence.Persistence;
    
    import org.apache.log4j.BasicConfigurator;
    import org.apache.log4j.Level;
    import org.apache.log4j.Logger;
    import org.junit.After;
    import org.junit.Before;
    import org.junit.Test;
    
    public class PersonTest {
        private EntityManagerFactory emf;
    
        private EntityManager em;
    
        @Before
        public void initEmfAndEm() {
            BasicConfigurator.configure();
            Logger.getLogger("org").setLevel(Level.ERROR);
    
            emf = Persistence.createEntityManagerFactory("examplePersistenceUnit");
            em = emf.createEntityManager();
        }
    
        @After
        public void cleanup() {
            em.close();
        }
    
        @Test
        public void emptyTest() {
        }
    }
    

    If it is, try to comment this line: “Logger.getLogger(“org”).setLevel(Level.ERROR);”. Or change it to “Logger.getLogger(“org”).setLevel(Level.ALL);”. Then you should see the errors on the output console.

    2 – In your persistence.xml I see you’re using hsqldb database. Did you installed/configured it properly?

    If you dont’t know this database, I suggest you use MySQL, PostgreSQL, or some database you are familiar with.

    3 – Check you persistence.xml. Mine is a little bite different:

    <?xml version="1.0" encoding="UTF-8"?>
    <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="App1PU" transaction-type="RESOURCE_LOCAL">
            <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
            <class>com.entities.User</class>
            <class>com.entities.Group</class>
            <properties>
                <property name="javax.persistence.jdbc.url" value="jdbc:mysql://myIP:3306/mydatabase"/>
                <property name="javax.persistence.jdbc.password" value="secret"/>
                <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
                <property name="javax.persistence.jdbc.user" value="myUser"/>
            </properties>
        </persistence-unit>
    </persistence>
    

    Notice the header has some XML declarations that might be important, since Hibernate is telling you that your file is incorrect.

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

Sidebar

Related Questions

i think this is a bit of a noob question, but here goes. I
This is probably a noob question that I will get slated for but here
Noob question here, my basic setup looks like this: (function($) { $.fn.imageSlider = function(options)
This is probably a java noob question but here is my scenario: using selenium,
a noob question here. I have the following code: - (IBAction)selectExistingPicture { if ([UIImagePickerController
This might sound like a noob question, but here it goes anyway. Can BlackBerry
a noob question here: any ideas why this code: UIViewController* popoverviewController = [[UIViewController alloc]init];
Ok this is potentially a noob question but here goes. Is it possible to
I guess this is a noob question, but here it comes: I have a
Total noob question, but here. CSS .product__specfield_8_arrow { /*background-image:url(../../upload/orng_bg_arrow.png); background-repeat:no-repeat;*/ background-color:#fc0; width:50px !important; height:33px

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.