jQuery in Action, 2nd edition*
The moose likes Object Relational Mapping and the fly likes JPA not working with EJB3  Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "JPA not working with EJB3  " Watch "JPA not working with EJB3  " New topic
Author

JPA not working with EJB3

Sam Woodard
Greenhorn

Joined: Jun 21, 2009
Posts: 5
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

Joined: Oct 23, 2003
Posts: 597
Why not inject EntityManager?
like following.

@PersistenceContext
private EntityManager manager;


Also use annotations for transactions.

@TransactionAttribute(TransactionAttributeType.REQUIRED)


Sandeep
Sam Woodard
Greenhorn

Joined: Jun 21, 2009
Posts: 5
I have tried it both ways. Same result.

Thanks,
Sam
Sandeep Awasthi
Ranch Hand

Joined: Oct 23, 2003
Posts: 597
I have done this on JBOSS 4.2. It works with Hibernate as JPA provider.
Sandeep Awasthi
Ranch Hand

Joined: Oct 23, 2003
Posts: 597


My persistence.xml
Sandeep Awasthi
Ranch Hand

Joined: Oct 23, 2003
Posts: 597
I am little confused, why are you using two seperate projects, ejb and JPA?
Sam Woodard
Greenhorn

Joined: Jun 21, 2009
Posts: 5
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

Joined: Oct 23, 2003
Posts: 597
Which application server are you using?
Sam Woodard
Greenhorn

Joined: Jun 21, 2009
Posts: 5
Glassfish
Sandeep Awasthi
Ranch Hand

Joined: Oct 23, 2003
Posts: 597
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.
 
wood burning stoves
 
subject: JPA not working with EJB3