-->
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: SecondaryTable with inverse join?
PostPosted: Thu Feb 22, 2007 4:25 pm 
Newbie

Joined: Fri Dec 01, 2006 12:13 pm
Posts: 3
I have two tables (see below).

FOO
----------------------------
FOO_ID(PK)
BAR_ID(FK)

BAR
----------------------------
BAR_ID(PK)
Name

I want to map these both to a single Foo entity using a Secondary Table.

@Entity
@Table(name="FOO")
@SecondaryTable(name="Bar", pkJoinColumns(@PrimaryKeyJoinColumn(name="BAR_ID", referencesColumnName="BAR_ID"))
public class Foo
{}

This didn't work, the below exception was thrown. Is there any way to map this?

Exception in thread "EntityManagerFactory Initializer" javax.persistence.PersistenceException: org.hibernate.AnnotationException: SecondaryTable JoinColumn cannot reference a non primary key
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:252)
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:120)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:51)
at com.surveysampling.emailpanel.ordereditor.resource.ResourceManager.initializeEntityManagerFactory(ResourceManager.java:302)
at com.surveysampling.emailpanel.ordereditor.resource.ResourceManager.access$0(ResourceManager.java:295)
at com.surveysampling.emailpanel.ordereditor.resource.ResourceManager$1.run(ResourceManager.java:87)
Caused by: org.hibernate.AnnotationException: SecondaryTable JoinColumn cannot reference a non primary key
at org.hibernate.cfg.annotations.TableBinder.bindFk(TableBinder.java:225)
at org.hibernate.cfg.annotations.EntityBinder.bindJoinToPersistentClass(EntityBinder.java:439)
at org.hibernate.cfg.annotations.EntityBinder.createPrimaryColumnsToSecondaryTable(EntityBinder.java:427)
at org.hibernate.cfg.annotations.EntityBinder.finalSecondaryTableBinding(EntityBinder.java:360)
at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:741)
at org.hibernate.cfg.AnnotationConfiguration.processArtifactsOfType(AnnotationConfiguration.java:452)
at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:268)
at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1115)
at org.hibernate.ejb.Ejb3Configuration.buildMappings(Ejb3Configuration.java:1233)
at org.hibernate.ejb.EventListenerConfigurator.configure(EventListenerConfigurator.java:154)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:869)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:183)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:240)
... 5 more


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 27, 2007 7:15 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
no relation with inverse, which is supported in SVN, but a join on a non pk is not supported by annotations. If you want to contribute, let me know.

_________________
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.