users@glassfish.java.net

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

From: Martin Gainty <mgainty_at_hotmail.com>
Date: Tue, 6 Apr 2010 22:44:34 -0400

have you implemented (EntityManager.persist) the object you want to persist

http://tudu.svn.sourceforge.net/viewvc/tudu/trunk/tudu2/tudu-core/src/main/java/tudu/domain/dao/jpa/UserDAOJpa.java?revision=480&view=markup


?
Martin
______________________________________________
Verzicht und Vertraulichkeitanmerkung/Note de déni et de confidentialité

Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene Empfaenger sein, so bitten wir hoeflich um eine Mitteilung. Jede unbefugte Weiterleitung oder Fertigung einer Kopie ist unzulaessig. Diese Nachricht dient lediglich dem Austausch von Informationen und entfaltet keine rechtliche Bindungswirkung. Aufgrund der leichten Manipulierbarkeit von E-Mails koennen wir keine Haftung fuer den Inhalt uebernehmen.

Ce message est confidentiel et peut être privilégié. Si vous n'êtes pas le destinataire prévu, nous te demandons avec bonté que pour satisfaire informez l'expéditeur. N'importe quelle diffusion non autorisée ou la copie de ceci est interdite. Ce message sert à l'information seulement et n'aura pas n'importe quel effet légalement obligatoire. Étant donné que les email peuvent facilement être sujets à la manipulation, nous ne pouvons accepter aucune responsabilité pour le contenu fourni.



 

> Date: Tue, 6 Apr 2010 18:41:07 -0700
> From: glassfish_at_javadesktop.org
> To: users_at_glassfish.dev.java.net
> Subject: JEE 6 / Glassfish v3 / Eclipse - JPA Entity Manager Issues
>
> Hey gang,
>
> This is my first post on the java.net forums. It seems like a very nice community, hopefully ya'll can help me out on my issue.
>
> I am creating a layered project
>
> - EAR Project
> - EJB Project
> - JPA Project
> - WAR Project
>
> Right now I have my web layer creating a new "user" entity with a username/password (via JSF 2.0 & AJAX; which is really cool).
>
> @ManagedBean(name = "userBeanUtil")
> @SessionScoped
> public class UserBeanUtil
> {
> private User user;
>
> public UserBeanUtil()
> {
> this.user = new User();
> }
>
> public User getUser()
> {
> return user;
> }
>
> public void setUser(User user)
> {
> this.user = user;
> }
>
> public void createUserAction(ActionEvent event)
> {
> DevUserController.update(user);
> }
>
> I then call the EJB layer UserController.update(user) hitting a local EJB which then calls an update method in my JPA layer.
>
> @LocalBean
> @Stateless
> public class UserController
> {
>
> /**
> * Default constructor.
> */
> public UserController()
> {
> }
>
> public static void update(User user)
> {
> UserHandler.persist(user);
> }
>
> }
>
> This layer will actually persist the data to the database. However, no matter how I try, I the "EntityManager" is always null.
>
> public class UserHandler
> {
> @PersistenceUnit(unitName = "MyPersistenceUnit")
> private static EntityManager em1;
>
> @PersistenceUnit(name = "MyPersistenceUnit")
> private static EntityManager em2;
>
> @PersistenceUnit
> private static EntityManager em3;
>
> @PersistenceContext(unitName = "MyPersistenceUnit")
> private static EntityManager em4;
>
> @PersistenceContext(unitName = "MyPersistenceUnit")
> private static EntityManager em5;
>
> @PersistenceContext
> private static EntityManager em6;
>
> public static void persist(User user)
> {
> em1.persist(user);
> }
>
> }
>
> Here is my persistence.xml file:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <persistence version="1.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_1_0.xsd">
> <persistence-unit name="MyPersistenceUnit" transaction-type="JTA">
> <jta-data-source>jdbc/RDF</jta-data-source>
> </persistence-unit>
> </persistence>
>
> Now, I did go through the MySQL / Glassfish V3 tutorial and setup a connection pool and JDBC Resource. I did a ping test on jdbc/RDF and it was successful.
>
> Long story short; I have no clue how come my EntityManager is not being injected.
>
> Anyone have any ideas?
>
> Hope I've given enough information. If not let me know; I'll be happy to provide more info.
>
> Also, if ya'll have links to "JEE6 Best Practices Documents" please feel free to share.
>
> Thanks,
> Chris
> [Message sent by forum member 'iceman3479']
>
> http://forums.java.net/jive/thread.jspa?messageID=395613
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>
                                               
_________________________________________________________________
The New Busy think 9 to 5 is a cute idea. Combine multiple calendars with Hotmail.
http://www.windowslive.com/campaign/thenewbusy?tile=multicalendar&ocid=PID28326::T:WLMTAGL:ON:WL:en-US:WM_HMP:042010_5