-->
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.  [ 5 posts ] 
Author Message
 Post subject: help with transactions
PostPosted: Wed Oct 22, 2003 8:57 pm 
Regular
Regular

Joined: Tue Aug 26, 2003 6:59 pm
Posts: 89
Location: Somewhere in the Ghetto
hi, im trying to get transactions to work but either I missed something very important in the docs or I dont know whats going on..

anyways heres the code im trying to run, i was expecting an ObjectNotFoundException to be thrown when trying to load the object at the end but its not happening, please help!


Session session = HibernateSession.currentSession();

session.setFlushMode(FlushMode.COMMIT);

Long userId = null;

Transaction tx = null;
try {
tx = session.beginTransaction();

User u = new User();
u.setName("testtx");
u.setPassword("testpassword");
session.save(u);

userId = u.getId();
System.out.println("User u: " + u);

tx.rollback();
} catch (Exception e) {
e.printStackTrace();
}

User ru = (User) session.load(User.class, userId); // shouldnt a ObjectNotFoundException be thrown here?
System.out.println("User ru: " + ru);

HibernateSession.closeSession();

this is the output:
User u: test.model.User@e22f2b[id=524289]
User ru: test.model.User@e22f2b[id=524289]


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 22, 2003 9:00 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Try flushing before you rollback.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 22, 2003 10:53 pm 
Regular
Regular

Joined: Tue Aug 26, 2003 6:59 pm
Posts: 89
Location: Somewhere in the Ghetto
ok i put session.flush() right before the call to tx.rollback() and got this exception:


[ERROR] JDBCTransaction - Rollback failed
java.sql.SQLException: General error: Warning: Some non-transactional changed tables couldn't be rolled back

whats going on here?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 23, 2003 12:14 am 
Regular
Regular

Joined: Tue Aug 26, 2003 6:59 pm
Posts: 89
Location: Somewhere in the Ghetto
ok i was able to track that error, it was from mysql, i had to create the tables as type innodb so I did that, but still trying to figure this transactions stuff out..


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 23, 2003 12:38 am 
Regular
Regular

Joined: Tue Aug 26, 2003 6:59 pm
Posts: 89
Location: Somewhere in the Ghetto
ok after more testing, turns out i had to evict the object right after the rollback because it was still in the session cache, this was not the behaviour i expected, so now its working as i thought it should have with output like this:

User u: test.model.User@1071c84[id=983041]
net.sf.hibernate.ObjectNotFoundException: No row with the given identifier exists: 983041, of class: test.model.User
at net.sf.hibernate.impl.SessionImpl.throwObjectNotFound(SessionImpl.java:1690)
at net.sf.hibernate.impl.SessionImpl.load(SessionImpl.java:1701)
at test.MiscTest.main(MiscTest.java:47)


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

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.