-->
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: MySQL DB with Hibernate Vs Oracle DB with hibernate
PostPosted: Thu Mar 10, 2011 11:12 am 
Newbie

Joined: Thu Mar 10, 2011 10:10 am
Posts: 1
Hi everybody,

I have a test with two sessions, session1 and session2.

I have the simple following code (I minimize it so it will be much clear to read).

//Session1
session1 = HibernateUtil.openSession();
session1.beginTransaction();
Repository rpy = new Repository(key);
session1.saveOrUpdate(rpy);
session1.flush();

//Session2
session2 = HibernateUtil.openSession();
session2.beginTransaction();
Repository rpy = new Repository(key);
session2.saveOrUpdate(rpy);

//commit and close session1
session1.getTransaction().commit();
session1.close();

session2.flush(); //should fail on uniqueConstrains ...

Repository rpy = new Repository(key);
session2.saveOrUpdate(rpy);
session2.flush(); //should NOT fail on uniqueConstrains (row already in the database)...

//commit and close session2
session2.getTransaction().commit();
session2.close();



session2 invoke saveOrUpdate(object) before session1 commit and close it transaction.
So actually session2, make a select to see if it should insert, or update it's data.
In that case since session1 still not committed, session2 will make insert after it make flush() and get org.hibernate.exception.ConstraintViolationException.
Till now, everything is ok ... I want to check that in some test in our system.

But, after I commit with session1 and make the same operation with session2 (i.e saveOrUpdate(obj) and then flush()) I am expecting to get update operation on the object since it's already in the DB.

I am working with hibernate.

It works fine with Oracle DB, but not as expected with MySQL (i.e with Oracle I get only once ConstraintViolationException and it updating in the second time, but I am getting twice ConstraintViolationException when I am working infront of MySQL DB)

Do, someone, now the reason why and how can I solve it???

I tried to remove second-level-cache in hibernate configuration file, I tried to change the CacheMode of the session, unfortunately, nothing helped.

Can you please, advice?

Best regards,

Ofer Nagar


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.