-->
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: Advanced Problems with Hibernate and Jboss !
PostPosted: Fri Nov 10, 2006 11:03 am 
Newbie

Joined: Fri Nov 10, 2006 10:23 am
Posts: 2
Hi every body,
Look at these classes examples to see my problems with hibernate on jboss (for a mySql database) and understand what i want to do :

@Entity
@Table(name=Mother)
@Inheritance(strategy = InheritanceType.JOINED)
public class Mother implements Serializable{
@Id
private String mother_id;
public Mother(){}

//... getters/setters generated for all fields members
}

Note : The Mother table has a single primary key : its id



@Embeddable
public Class DaughterKey implements Serializable{
private String mother_Id;
private String daughter_id;
public DaughterKey(){}

//getters/setters generated for the both fields

// the methods : toString(),hasCode(),equals() are overrided
}

Note : the DaughterKey is a class that specifies (according to my understandings) a composite primary key class when mappings happen !



@Entity
@Table(name = "Daughter")
@IdClass(DaughterKey.class)
@PrimaryKeyJoinColumn(name = "Mother_id")
public class Daughter extends Mother{
@Id
private String daughter_id;
public Daughter(){ super();}

//.. getter/setter for all fields
}

Note: the Daughter table has a composite key (mother_Id+daughter_id).




So,the idea is that eventhough a Daughter Class extends a Mother Class, the Daughter must have 2 fields-members as PrimaryKey in the Database (the mother_id and its own daughter_id) : a composite key.

After compiling and creating a JAR file, I try to deploy the JAR-file and i have a such exception :

java.lang.reflect.InvocationTargetException
//.... at ....
caused by

org.hibernate.AnnotationException : Unable to define/override @Id(s) on a subclass : Daughter.

Thanks a lot if someOne can help me, I know that it's because my conception is not correct but I can't get any better ided.


PS : Ask your questions, if you don't understand my idea !
Best regards, Divx.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 24, 2006 11:15 am 
Newbie

Joined: Tue Mar 08, 2005 8:00 am
Posts: 10
Mother_id has to be unique itself, because in a joined inheritance every instance of the subclass has a row even in the "mother" table.
If mother_id is unique, why bother to declare daughter_id part of the primary key?
Just map it as a property.


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.