Win a copy of Spark in Action this week in the Open Source Projects forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
  • Piet Souris
  • Frits Walraven
  • Carey Brown

JPA Newbie Question

Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:



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
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
Message for you sir! I think it is a tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    Bookmark Topic Watch Topic
  • New Topic