-->
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.  [ 4 posts ] 
Author Message
 Post subject: I want to use another class as the Id, but its not composite
PostPosted: Tue Oct 02, 2007 7:18 am 
Beginner
Beginner

Joined: Tue Jun 27, 2006 6:14 am
Posts: 24
Hibernate version:
Hibernate Annotations 3.3.0.GA
Hibernate 3.2.5

Mapping documents:
Annotations:

Quote:
class Extension{

@Id
public int getId() {
return getOriginal().getId();
}

@OneToOne
public Inst getOriginal() {
return orig;
}
}


Name and version of the database you are using:
Oracle 10g


We have an extension type table, where there is at most one entry in the extension table per row in the original. There might be none.

The Id of the original table is thus the Id of the extension table. I also want to access the original table from the extension.

The above code is what I currently have. I tried putting the @Id on the getOriginal method, but that complains about the type of the original.

Quote:
org.hibernate.MappingException: Could not determine type for: com.Original, for columns: [org.hibernate.mapping.Column(original)]


With the above code, it forces me to create a setter for the Id on the extension table, but that does not make sense as its set by setting the original object onto the extension object.

I am probably doing this the wrong way - any tips/pointers?

Thanks in advance,
Chris[/quote]


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 03, 2007 10:39 am 
Beginner
Beginner

Joined: Tue Jun 27, 2006 6:14 am
Posts: 24
bump... Am I just trying to use hibernate incorrectly or is there a trick to what I am doing?

Thanks in advance,
Chris


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 03, 2007 12:39 pm 
Newbie

Joined: Tue Oct 02, 2007 4:48 am
Posts: 9
As far as I know you can't just annotate @Id on a getter method without getter having a field declared in the same class. The other mistake I see is getOriginal() method and field orig - they should be named the same. If the field is orig, the getter should be named getOrig() otherwise hibernate cannot associate the getter with the field.

Also I don't agree that both entities share the same primary key but each entity should have its own PK with Extension a foreign key to Original. Alternative to this is only composite.

I don't know if I was any help but I tried my best. ;)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 04, 2007 2:09 am 
Beginner
Beginner

Joined: Tue Jun 27, 2006 6:14 am
Posts: 24
Hi,

Thanks for the reply - I was keen to get a separate key on the entity, but my colleague seems to think its a better reflection of the underlying data...

My other solution was to have both the original object and its key on the extension class - with a hack that when you set the original object, it also set the key - but it really is a hack :(.

Thanks,
Chris


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