IntelliJ open source
[Logo] JavaRanch » Big Moose Saloon
  Search | FAQ | Recent Topics | Hot Topics
Register / Login


Reply Bookmark it! Watch this topic JavaRanch » Forums » Professional Certification » EJB Certification (SCBCD)
 
RSS feed
 
New topic
Author

Doubt regarding Transaction in Entities

Jothi Shankar Kumar
Ranch Hand

Joined: Sep 26, 2006
Messages: 7093

Guys,

There is a method called contains() that we can invoke on an Entity to check if that entity is available in the PersistenceContext. Likewise is there any way to attach an entity to a PersistenceContext apart from operating it using the entity operations like find() and getReference()?

SCJP 1.4, SCWCD 1.4 - Hints for you, SCBCD Hints - Demnachst, SCDJWS - Auch Demnachst
Did a rm -R / to find out that I lost my entire Linux installation!
Mihai Radulescu
Ranch Hand

Joined: Sep 18, 2003
Messages: 893

Hi Jothi

The merge method is used (also) to attach an entity to context.
I think the answer to your question is no, there is nothing like attach method - there are a lot of tricks bue each one has pros and contras.

Regards
Mihai

This message was edited 1 time. Last update was at by Mihai Radulescu


SCJP, SCJD, SCWCD
Minu Jain
Ranch Hand

Joined: Mar 24, 2008
Messages: 60

There are 3 methods mainly that attach an entity(when an entity becomes managed).
persist()
find()
merge()

Hope this helps answer your query!

chasing SCBCD
SCJP 5, SCWCD 5
"Even if you're on the right track, you'll get run over if you just sit there."
Mihai Radulescu
Ranch Hand

Joined: Sep 18, 2003
Messages: 893

Hi Minu,

Dont forget the createQuery():Query from the EntityManager. If is trigger isn a transaction then the entities resulted are attached to the corresponding persistnce context.

Regards,
Mihai

This message was edited 1 time. Last update was at by Mihai Radulescu


SCJP, SCJD, SCWCD
 
 
 
Reply Bookmark it! Watch this topic JavaRanch » Forums » Professional Certification » EJB Certification (SCBCD)
 
RSS feed
 
New topic
IntelliJ open source