-->
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: OneToMany in SecondaryTable
PostPosted: Tue Oct 02, 2007 4:07 am 
Newbie

Joined: Mon Oct 01, 2007 12:42 pm
Posts: 13
Location: Helsinki, Finland
I have a problem with foreign keys created for OneToMany relationship in secondary table.
I am using Hibernate Core 3.2.5.GA and Hibernate Annotations 3.3.0.GA.
Please take a look at the example classes and annotations.

Abstract superclass:

Code:
@Entity
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name="category",discriminatorType=DiscriminatorType.CHAR)
@DiscriminatorValue("@")
public abstract class Product {

   @Id
   @GeneratedValue(strategy=GenerationType.AUTO)
   private int id;

   // ... more attributes ...
}



Several subclasses, one particularly interesting:

Code:
@Entity
@DiscriminatorValue("W")
@SecondaryTable(name="WineProduct")
public class WineProduct extends Product {

   private float alcoholicStrength;

   // ... more attributes persisted in Product ...

   @Column(table="WineProduct")
   private String wineGrowingZone;

   // ... more attributes persisted in WineProduct ...


   @OneToMany
   @JoinColumn(name="product_id",nullable=false)
   private List<WineOperation> wineOperations;
}


And WineOperation:

Code:
@Entity
public class WineOperation {

   @Id
   @GeneratedValue(strategy=GenerationType.AUTO)
   private int id;

   // ... more attributes ...
}



I am using Hibernate to generate the database schema. The problem is that the foreign key created for @OneToMany is not what I want it to be: it is WineOperation --> Product instead of WineOperation --> WineProduct.

After changing @JoinColumn annotation in WineProduct to (is this even correct?):

Code:
@JoinColumn(table="WineProduct",name="product_id",nullable=false)


I get the folowing exception: org.hibernate.cfg.NotYetImplementedException: Collections having FK in secondary table


Any ideas how to get the foreign key created correctly?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 19, 2007 4:42 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
you can change the DDL manually

_________________
Emmanuel


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.