-->
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: Annotation: Inheritence on primary key classes
PostPosted: Wed Apr 20, 2005 6:44 am 
Newbie

Joined: Tue Apr 19, 2005 11:41 am
Posts: 2
Location: Oldenburg, Germany
Hi,

I would like to use primary key classes in a hierarchy:

Code:
@Embeddable (access=AccessType.PROPERTY)
public class Cls1PK implements Serializable {
    int id1;
   
    public int getID1() {
        return id1;
    }

    .... hashCode, equals ...
}


and

Code:
@Embeddable (access=AccessType.PROPERTY)
public class Cls2PK extends Cls1PK {
    int id2;

    public int getID2() {
        return id2;
    }
}


but it doesn't seem to work.

If I use Cls2PK as @Id in some class like Cls2 Hibernate uses ID2 of class Cls2PK but ignores property ID1. That leeds to too short where clauses in update statements.

Is it just not specified to work that way? Every example file in Hibernate seems to use PK base classes without any hierarchy.

If I rewrite my class as

Code:
@Embeddable (access=AccessType.PROPERTY)
public class Cls2PK extends Cls1PK {
    int id2;

    public int getID1() {
        return super.getID1();
    }

    public int getID2() {
        return id2;
    }
}



everything works fine. But that's redundant code, isn't it?

The Annotation Version is "Version: 3.0beta1 Preview" based on EJB3 EDR2.

Thank you
Carsten


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 20, 2005 7:09 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Component and thus composite id class inheritance is not supported by hibernate. Sorry about that.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 20, 2005 7:18 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
it is supported if you write usertypes for the composite pk's....its doable ;)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 21, 2005 4:15 am 
Newbie

Joined: Tue Apr 19, 2005 11:41 am
Posts: 2
Location: Oldenburg, Germany
usertypes seems to be possible, but they couple a lot of my classes close to hibernate

anyway a good hint, because i found them essential at another important place

thank you


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 21, 2005 4:25 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
No usertypes does not tie your pojo's to hibernate.

Your UserType will be dependent on Hibernate, but your primarykey classes should not BE the UserType - you should have 2 different classes.

_________________
Max
Don't forget to rate


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.