-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Error making rollback after an persist and query
PostPosted: Fri Mar 13, 2009 4:29 pm 
Newbie

Joined: Thu Feb 07, 2008 5:58 pm
Posts: 1
Hi,

I'm having problems while making rollback of a transaction after persist a new entity and executing a query on it.

Code:
TesteEJB teste=new TesteEJB();
teste.setCancelable(false);
teste.setFirst(true);
teste.setHelp("OK");

em.persist(teste);

System.out.println(teste);

TesteEJB find = em.find(TesteEJB.class, teste.getId());

System.out.println(find);

List<TesteEJB> list=em.createQuery("from TesteEJB t where t.id=?")
.setParameter(1, teste.getId())
.getResultList();

for(int i=0;i<list.size();i++) {
   System.out.println(list.get(i));
}

context.setRollbackOnly();


The entity manager and context are being injected.

Code:
@PersistenceContext(unitName = "gwf")
public EntityManager em; // injected by persistenceContext

@Resource
private SessionContext context;// injected by persistenceContext


After running this code, the entity is available in the database.
I’m running this code on JBoss 4.2.2 with an Oracle 9i database.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.