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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:08:09+00:00 2026-05-25T06:08:09+00:00

I’m using : Eclipse Java EE IDE Web Developers version:Indigo Release with hibernate tools,

  • 0

I’m using :
Eclipse Java EE IDE Web Developers
version:Indigo Release

with hibernate tools, i’m new to hibernate in Eclipse, so i learn how configure the hibernate and generate the POJO’s with annotations (which i think is better than .xml).

So after generate my POJO’s and DAO’s i try to make a insertion, but launch a ‘null point exception’ to my entity manager, this is how hibernate tools is generating the dao classes:

Trying to use the DAO generated:

public static void main(String[] args) {
// TODO Auto-generated method stub
    User user = new User();
    user.setEmail("valter@brainset.com.br");
    user.setPassword("123456");
    user.setReputation(0);

    DaoUser daoUser = new DaoUser();
    daoUser.persist(user);
}

DAO generated:

package com.example.pojo;

// Generated 30/08/2011 20:43:29 by Hibernate Tools 3.4.0.CR1

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * Home object for domain model class User.
 * @see com.example.pojo.User
 * @author Hibernate Tools
 */
@Stateless
public class UserHome {

    private static final Log log = LogFactory.getLog(UserHome.class);

    @PersistenceContext
    private EntityManager entityManager;

    public void persist(User transientInstance) {
        log.debug("persisting User instance");
        try {
            entityManager.persist(transientInstance);
            log.debug("persist successful");
        } catch (RuntimeException re) {
            log.error("persist failed", re);
            throw re;
        }
    }

    public void remove(User persistentInstance) {
        log.debug("removing User instance");
        try {
            entityManager.remove(persistentInstance);
            log.debug("remove successful");
        } catch (RuntimeException re) {
            log.error("remove failed", re);
            throw re;
        }
    }

    public User merge(User detachedInstance) {
        log.debug("merging User instance");
        try {
            User result = entityManager.merge(detachedInstance);
            log.debug("merge successful");
            return result;
        } catch (RuntimeException re) {
            log.error("merge failed", re);
            throw re;
        }
    }

    public User findById(Integer id) {
        log.debug("getting User instance with id: " + id);
        try {
            User instance = entityManager.find(User.class, id);
            log.debug("get successful");
            return instance;
        } catch (RuntimeException re) {
            log.error("get failed", re);
            throw re;
        }
    }
}

I think i must be doing something wrong in the configuration process.
How should I set correctly my classes and dao’s ?

  • 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-25T06:08:10+00:00Added an answer on May 25, 2026 at 6:08 am

    How are you injecting in your entity manager? By the looks of it, you are trying to run an enterprise application in SE.

    If you really need this to run in SE (hence the “main” method) you’ll need to bootstrap the persistence engine somehow.

    I usually provide a setter to the entity manager or provide an abstract getter. From there you can do something like this:

        _entityManagerFactory = Persistence.createEntityManagerFactory( "myJDBC" );
        _entityManager = _entityManagerFactory.createEntityManager();
    
        UserHome userHome = new UserHome();
        userHome.setEntityManger( _entityManager );
    

    You’ll also need a peristence.xml file with a persistence unit matching whatever you end up calling “myJDBC”.

    I hope this helps.

    EDIT #1

    There is an example here that I think will help you out. It is a helloworld with JPA, Toplink and MySQL, though the MySQL part does not matter, you can switch your driver out if needs be.

    EDIT #2

    There is also an example here that uses hibernate only (not so much JPA).

    EDIT #3

    I think the output from the hibernate tools in the enterprise Eclipse tooling is geared towards that: enterprise java. That being said, it is much easier to take what you have and run it in EE. That isn’t to say that you can’t run it in SE, just that it is a little more challenging.

    On that note, whenever I use hibernate in SE without JPA, I augment it with Spring – this takes the load off significantly. I wouldn’t worry about that until you get it working, but I’d consider looking at it once you’ve learned a few lessons about hibernate and\or JPA.

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

Sidebar

Related Questions

I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
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
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I want use html5's new tag to play a wav file (currently only supported
Seemingly simple, but I cannot find anything relevant on the web. What is the
I'm making a simple page using Google Maps API 3. My first. One marker
We're building an app, our first using Rails 3, and we're having to build
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this

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.