• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

detached entity passed to persist

 
Amol Katyare
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am using JPA for persistence. Since I am on EJB 2.1 am not able to avail injection technique for getting EntityManager object. Below is my code snippet:



But I get an excpetion "detached entity passed to persist".

I tried to browse the information on this but it looks like the people who could solve this problem are using injected entity manager.

Could you please explain how can I resolve this error?

Please note that I am successfully able to run all the remaining APIs like merge, createQuery, find, etc.. with the entity manager on the same Person entity.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since you don't have injection, you also don't get the transaction. You need to get a Transation from the Entity Manager and start it up, then at the end commit the transaction.

Mark
 
Amol Katyare
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the confirmation. Can I use injection technique with EJB 2.1 and/or in web only project? I am on EJB 2.1 and I tried to use injection technique but somehow entity manager is not getting injected by container and I get Null pointer exception.


Could you please throw some light on this and how I would be able to use transaction in EJB 2.1?
 
Amol Katyare
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any reply please ??
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Amol Katyare:
Thanks for the confirmation. Can I use injection technique with EJB 2.1 and/or in web only project? I am on EJB 2.1 and I tried to use injection technique but somehow entity manager is not getting injected by container and I get Null pointer exception.


Could you please throw some light on this and how I would be able to use transaction in EJB 2.1?


No, EJB 2.1 has no concept of Dependency Injection.

In EJB 2.1 you just use the other technique of calling Transaction t = session.beginTransaction();

then when you want to commit or rollback you call the method on Transaction class.

Mark
Mark
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic