-->
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: @Version works when integer but fails when timestamp
PostPosted: Sun Feb 04, 2007 5:23 pm 
Newbie

Joined: Wed Jan 31, 2007 12:48 pm
Posts: 6
Hello,

I am having a problem with the @Version tag in combination with a timestamp (mysql5, hibernate 3.2.2)


I have a simple bean with id, name and version attributes.

The following code fragment

EntityManagerFactory emf = Persistence.createEntityManagerFactory(System.getProperty("EntityManager"));
EntityManager em=emf.createEntityManager();
EntityTransaction tx1=em.getTransaction();
tx1.begin();
Role r1=new Role();
r1.setName("role");
em.persist(r1);
tx1.commit();
em.clear();
EntityTransaction tx2=em.getTransaction();
tx2.begin();
r1=em.merge(r1);
em.remove(r1);
tx2.commit();

When I have a int @Version attribute the code seems to work fine, but with a Timestamp version I get

javax.persistence.OptimisticLockException: org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [com.luma.w2p.model.Role#5]
at org.hibernate.ejb.AbstractEntityManagerImpl.wrapStaleStateException(AbstractEntityManagerImpl.java:645)
at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:599)
at org.hibernate.ejb.AbstractEntityManagerImpl.merge(AbstractEntityManagerImpl.java:236)


Is there something wrong with the code? Or is this a (known) issue in Hibernate (the glassfish/toplink ri) also works for Timestamp version attribute.

Thanks,

Peter


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 05, 2007 12:02 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
check how the timestamp is stored into the db. it has probably changed somehow

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 05, 2007 6:39 pm 
Newbie

Joined: Wed Jan 31, 2007 12:48 pm
Posts: 6
It looks like it yes. If I fetch the version timestamp column the nano's part is gone, while the version attribute in the Role does contain it.

Unfortunately that does not really bring me much closer to a solution. My closest guess is that something is wrong with the jdbc and/or mysql installation/configuration.

Anyone any (other) thoughts?

Thanks!

Peter


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 05, 2007 7:11 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
As a workaround you could subclass TimestampType and change isEqual() to behave like Toplink, ie ignore the nano's part and use @Type. Kinda sucks but at least it will work

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 06, 2007 3:05 am 
Newbie

Joined: Wed Jan 31, 2007 12:48 pm
Posts: 6
Thanks for your help. I'll probably stick with integers instead...or switch databases.


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.