-->
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.  [ 2 posts ] 
Author Message
 Post subject: @MappedSuperclass and @Version (Bug?)
PostPosted: Thu Dec 31, 2009 2:21 pm 
Newbie

Joined: Thu Dec 31, 2009 2:04 pm
Posts: 2
Hi, I'm having two problems with @Version mapped in a @MappedSuperClass class.

This is a preview of my AbstractEntiy:
Code:
@MappedSuperclass
public abstract class AbstractEntity<PK extends Serializable> implements Serializable {
    @Transient
    @Column(name = "id")
    public PK getPrimaryKey() {
        return primaryKey;
    }

    @Version
    @Column(name = "version", nullable = false)
    public int getVersion() {
        return version;
    }
    }


My first problem was that whenever I added the @Version to a field instead of a property, my version number wouldn't be updated at all.
I still don't know why this was happening, but at least I could make it work by adding the annotation to the property instead.

Now, my real problem and perharps a bug? happens when I try to update my Usr class which extends AbstractEntity.

When I use
Usr user = userDao.update(user);

My user is updated correctly in the database, including it's version number. My variable (user) is also update, however the version field remains the same, old number. What could be happening?

Example:
Code:
BEFORE UPDATE:

Database: Version 1, Name: Bruno
Java: Version 1, Name: Bruno

AFTER UPDATE:
Database: Version 2, Name: Bruno Pinto
Java: Version 1, Name: Bruno Pinto


Top
 Profile  
 
 Post subject: Re: @MappedSuperclass and @Version (Bug?)
PostPosted: Thu Dec 31, 2009 2:30 pm 
Newbie

Joined: Thu Dec 31, 2009 2:04 pm
Posts: 2
I can't believed I managed to fix it! =D

My problem was that my GenericDaoHibernate update method was calling merge instead of update. However, shouldn't my version be update even when calling merge?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.