aspose file tools*
The moose likes Object Relational Mapping and the fly likes JPA Newbie Question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "JPA Newbie Question" Watch "JPA Newbie Question" New topic
Author

JPA Newbie Question

Frank Jones
Greenhorn

Joined: Aug 29, 2011
Posts: 8
Hi, I'm trying to set up my first JPA app, and while I'm able to get it to work outside a J2EE container, or within a J2EE container using the following code:


I'm unable to get it to work using the @PersistenceContext annotation. My understanding was that the two below things would both successfully load the EntityManager in the same 'em' reference:

1..


2..


But when I run option 2, I get this error:


I'm sure there's something dumb I'm missing, but if anyone could tell me what it is, I'd be grateful

ps. I am using JBoss 6 and MySQL, if that is relevant.


Frank Jones
Greenhorn

Joined: Aug 29, 2011
Posts: 8
Ok I've fixed it, I'll post up what I did in case it saves somebody else the headache I've had trying to get this to work

I think there was two things I did wrong, first I think I was supposed to set 'unitName' on the persistence context, not 'name':



Secondly I packaged the application wrong, I had an ear file, with a WAR, an EJB JAR, a plain JAR and a persistence unit JAR, all in the root. I changed it so that only the WAR and EJB JAR were in the root, and the plain JAR and persistence unit JAR were in the lib subdirectory of the EAR.
 
Don't get me started about those stupid light bulbs.
 
subject: JPA Newbie Question
 
Similar Threads
nullPointerException on entity manager methods
Persistence IllegalArgumentException in EntityManager
EntityManager types in JPA
not able to insert data in db using jpa(hibernate as provider) and jboss AS
EntityManager is null when I try to use it straight from filter servlet