This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Little Book of Impediments (e-book only) and have Tom Perry on-line!
See this thread for details.
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

Transaction Scoped Context

 
Nikhil Jain
Ranch Hand
Posts: 392
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
According to spec, the object returned from the find method is detached object. When I run the same on JBOSS, i get it managed. This is being checked using Entity Manager's contain method. I am using Transaction scoped context
 
Mirko Bonasorte
Ranch Hand
Posts: 244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
the object will result as detached if you are not in a transaction.
Consider that if you return the object from an ejb method with its own transaction, this could happen.
Can you post your code?
 
Nikhil Jain
Ranch Hand
Posts: 392
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah you are right

@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
public void findUser() {
em.getTransaction();
User user = em.find(User.class, 2);
System.out.println(user.getName());
System.out.println(em.contains(user));
}

This prints false.

with required,

it prints true.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic