-->
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: Foreing keys using generics not working as expected
PostPosted: Tue Nov 10, 2009 7:11 am 
Newbie

Joined: Wed Dec 10, 2008 6:39 am
Posts: 6
Hello, I'm using Hibernate on JBoss 4.3.2 using standard JPA annotations. I have the following classes:

Code:
@Entity
@Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)
public abstract class A {
}

@Entity
@Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)
public abstract class B<T extends A> {

  @OneToOne
  private T foreing;
}

@Entity
public class A1 extends A {
}

@Entity
public class A2 extends A {
}

@Entity
public class B1 extends B<A1> {
}

@Entity
public class B2 extends B<A2> {
}


With this code, I expect to get a table B1 with a foreign key to A1 and B2 with a foreign key to A2 but instead I get two tables (B1 and B2) with foreign keys to A1. I don't know if I'm doing something wrong or if this cannot be implemented but I don't know why A1 is selected in both cases. The compiler is supposed to replace T with A1 and A2 in B1 and B2 respectively, isn't it? Then, why B2 is picking A1 instead of A2?


Top
 Profile  
 
 Post subject: Re: Foreing keys using generics not working as expected
PostPosted: Tue Nov 10, 2009 10:38 am 
Newbie

Joined: Wed Dec 10, 2008 6:39 am
Posts: 6
Nevermind, I solved it putting @MappedSuperclass in class B instead of Entity.


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.