Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JPA not working with EJB3

 
Sam Woodard
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have the following code in my ejb



i am getting,



f have put both toplink jars in the lib directory of the server, of the domain, in the ear and in both projects, the java jpa project and the ejb project, with no success.

My persistence.xml looks like this:



Any help would be greatly appreciated.

Thanks in advance,
Sam
 
Sandeep Awasthi
Ranch Hand
Posts: 597
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why not inject EntityManager?
like following.

@PersistenceContext
private EntityManager manager;


Also use annotations for transactions.

@TransactionAttribute(TransactionAttributeType.REQUIRED)
 
Sam Woodard
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have tried it both ways. Same result.

Thanks,
Sam
 
Sandeep Awasthi
Ranch Hand
Posts: 597
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have done this on JBOSS 4.2. It works with Hibernate as JPA provider.
 
Sandeep Awasthi
Ranch Hand
Posts: 597
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


My persistence.xml
 
Sandeep Awasthi
Ranch Hand
Posts: 597
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am little confused, why are you using two seperate projects, ejb and JPA?
 
Sam Woodard
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
2 reasons:

1) To separate the model from the business logic.
2) Eclipse provides additional functionality for ddl generation, etc for jpa projects
 
Sandeep Awasthi
Ranch Hand
Posts: 597
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which application server are you using?
 
Sam Woodard
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Glassfish
 
Sandeep Awasthi
Ranch Hand
Posts: 597
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My suggestion is

1) First try with simple example to create a session bean (In one project, do not use two projects). For example sayHello.
2) If that works, then create one test pojo class which will map to a table.
3) create persistence.xml in META-INF directory
4) Inject EntityManager in your session bean and try to pesist pojo from session bean.

Search for simple tutorial, it will work.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic