-->
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.  [ 3 posts ] 
Author Message
 Post subject: Annotations - no primary key - <C extends T> generics
PostPosted: Wed Mar 15, 2006 9:29 pm 
Newbie

Joined: Wed Mar 15, 2006 8:45 pm
Posts: 2
Hibernate version: 3.1
Hibernate Annotations version: 3.1beta8

Annotations are generating an association table with two columns each with foreign keys. That is all correct
The problem is that both columns should also be primary keys - they are not. The table gets no primary key at all.

The following has worked previously with mapping normal generic collections. The only difference in this situation is that the class is using the <C extends Version>. This makes the generic collections type unknown at compile time, which appears to be the issue.

This is the BassClass which contains the property which should be mapped as the primary key
Code:
@MappedSuperclass
public abstract class BaseClass
{
   private Long id;

   @Id @GeneratedValue(strategy=GenerationType.AUTO )
   public final Long getId()
   {
      return id;
   }
   ...
}



This is the base version class that is on the other side of the one to many relationship.
Code:
@Entity
Class Version extends BaseClass
{
   ...
}




This is the class with the mapping information.
Code:
@Entity
public class History<C extends Version> extends BaseClass
{
   private List<C> versions;
   ...

   @OneToMany( targetEntity=Version.class )
   public List<C> getVersions()
   {
      return versions;
   }

   ...
}


Is there something wrong with this mapping (shouldnt be)

This maybe a small bug in the annotations that prevents it from finding the key when the type is not well defined using generics.

If it isnt a bug what am I doing wrong - If it is, is there a work around.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 16, 2006 2:32 am 
Beginner
Beginner

Joined: Sat Sep 17, 2005 10:41 am
Posts: 49
The mapping is working as it should. Hibernate creates a join table containing foreign key references to your two associated tables. The table doesn't have a simple primary key, but (I believe) there should be a unique constraint on those two foreign keys, effectively making them a composite primary key.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 16, 2006 6:54 pm 
Newbie

Joined: Wed Mar 15, 2006 8:45 pm
Posts: 2
Thanks for your reply
Yes your correct it is identifing one of the columns as being unique. However, in a similar situation shown below, it still creates the unique key but also creates the primary key


Code:
@Entity
public class History extends BaseClass
{
   private List<Version> versions;
   ...

   @OneToMany( targetEntity=Version.class )
   public List<Version> getVersions()
   {
      return versions;
   }

   ...
}


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