Hello,
I must map an existing model that's more or less like that :
- A has a foreign key to B;
- Each one of A and B has a part of a foreign key to C
The mapping I tried until now is like that :
Code:
@Entity
class A {
@Id(name="A_ID")
public Long key;
@Column(name="A_CID1")
public Long fkToC;
@JoinColumn(name="A_BID", referencedColumnName="B_ID")
public B b;
}
@Entity @Secondarytable(name="A")
class B {
@Id(name="B_ID")
public Long key;
@Column(name="B_CID2")
public Long fkToC;
@JoinColumns({
@JoinColumn(table="A", name="fkToC", updatable=false, insertable=false),
@JoinColumn(table="B", name="fkToC", updatable=false, insertable=false)
})
public C c;
}
@Entity
class C {
@Column(name=C_ID1)
public Long id1;
@Column(name=C_ID2)
public Long id2;
}
It seems it won't work, as I get somme error :
Code:
Caused by: org.hibernate.AnnotationException: Mixing different tables in a property is not allowed: com.cs.services.bcmail.entity.MonitoringEventmonitoringReport
at org.hibernate.cfg.Ejb3Column.checkPropertyConsistency(Ejb3Column.java:424)
at org.hibernate.cfg.AnnotationBinder.bindManyToOne(AnnotationBinder.java:1982)
at org.hibernate.cfg.AnnotationBinder.processElementAnnotations(AnnotationBinder.java:1362)
at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:755)
at org.hibernate.cfg.AnnotationConfiguration.processArtifactsOfType(AnnotationConfiguration.java:546)
at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:291)
at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1161)
at org.hibernate.ejb.Ejb3Configuration.buildMappings(Ejb3Configuration.java:1227)
at org.hibernate.ejb.EventListenerConfigurator.configure(EventListenerConfigurator.java:173)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:855)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:426)
at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:132)
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:225)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:310)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1479)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1419)
... 43 more
I'd like to
- make sure is really what I understand, i.e. one cannot have a join over columns from different tables
- find out how this can be mapped if it is not possible to do it like I tried.
Edit : added forgotten "updatable", "insertable".
Edit2 : added class C.