users@glassfish.java.net

Re: JEE 6 / Glassfish v3 / Eclipse - JPA Entity Manager Issues

From: Sahoo <Sahoo_at_Sun.COM>
Date: Thu, 08 Apr 2010 19:43:42 +0530

There is nothing wrong with your persistence.xml or with your EJB. I
think you are not invoking the EJB correctly from your JSF managed bean.
Looking at your first posting, I have a feeling you are directly calling
the EJB class instead of obtaining an EJB reference via @EJB. So, do
something like this in your managed bean:

@ManagedBean(name = "userBeanUtil")
@SessionScoped
public class UserBeanUtil
{
        @EJB UserController userController;

        private User user;

        ...
        
        public void createUserAction(ActionEvent event)
        {
                userController.insert(user);
        }
}


Thanks,
Sahoo

glassfish_at_javadesktop.org wrote:
> Alrighty guys, I took the advice and ended up restructuring my project.
>
> EAR
> - EJB
> - WAR
>
> My EJB project has the JPA facet so I could use Eclipse to generate Entities from the database tables. There I also have my persistence.xml
>
> Persistence.xml
> ============
> <?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="jdbc/RDF" transaction-type="JTA">
> <jta-data-source>jdbc/RDF</jta-data-source>
> <properties/>
> </persistence-unit>
> </persistence>
>
> EJB
> ====
> @LocalBean
> @Stateless
> public class UserController
> {
> @PersistenceContext(unitName = "jdbc/RDF")
> private EntityManager em1;
>
> @PersistenceContext(unitName = "jdbc/RDF")
> private EntityManager em2;
>
> @PersistenceContext
> private EntityManager em3;
>
> @PersistenceContext(name = "jdbc/RDF")
> private EntityManager em4;
>
> @PersistenceContext(name = "jdbc/RDF")
> private EntityManager em5;
>
> @PersistenceContext
> private EntityManager em6;
>
> public UserController()
> {
> }
>
> public void insert(User user)
> {
> em1.persist(user);
> }
>
> }
>
> Once again.... all of my entity managers are NULL.
>
> Any other thoughts?
> [Message sent by forum member 'iceman3479']
>
> http://forums.java.net/jive/thread.jspa?messageID=395815
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>
>