-->
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: @Version and Inheritance
PostPosted: Sat Oct 10, 2009 5:32 am 
Newbie

Joined: Sat Oct 10, 2009 5:20 am
Posts: 2
Hi,

I need help with @Version and Inheritance. This is what I am doing.

@MappedSuperclass
class BaseClass{

@Version
@Column(name = "version")
int version;
...
}

@Inheritance(strategy = InheritanceType.JOINED)
@Table(name = "A")
class A extends BaseClass {
...
}

@Table(name = "B")
class B extends A {
...
}
}

Physical table for B has a version and so does A. When I try to insert arecord in B I get the folowing error:

Caused by: java.sql.SQLException: Field 'version' doesn't have a default value
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1055)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)

How do I add @Version in Table A and B. Is it possible?


Top
 Profile  
 
 Post subject: Re: @Version and Inheritance
PostPosted: Tue Oct 20, 2009 3:50 pm 
Beginner
Beginner

Joined: Tue Dec 27, 2005 1:13 pm
Posts: 25
Location: Kingston, ON, Canada
The JOINED inheritance type is a ONE-TO-ONE relationship. Every record in table B must have a related record in table A.
When you change a field of object B (wheather the field in Table A or B), the version in table A will be changed. So, you don't need another version field in TABLE B.


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.