java – org. hibernate. Annotationexception: the referencedcolumnnames reference is not mapped to a single property
•
Java
I encountered the following exception when mapping one-to-one between two entities The first entity embeds a composite key The second entity also has embedded composite keys These tables are part of the legacy system The data are flat and the relationship definition is not clear Please help.
Caused by: org.hibernate.AnnotationException: referencedColumnNames(FLAG_NAME) of net.javabeat.spring.model.ReferralsM.mnEditFlag referencing net.javabeat.spring.model.MnEditFlag not mapped to a single property at org.hibernate.cfg.BinderHelper.createSyntheticPropertyReference(BinderHelper.java:205) at org.hibernate.cfg.ToOneFkSecondPass.doSecondPass(ToOneFkSecondPass.java:116) at org.hibernate.cfg.Configuration.processEndOfQueue(Configuration.java:1515) at org.hibernate.cfg.Configuration.processFkSecondPassInOrder(Configuration.java:1440) at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1358) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1727) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1778) at org.springframework.orm.hibernate4.LocalSessionFactoryBuilder.buildSessionFactory(LocalSessionFactoryBuilder.java:247) at org.springframework.orm.hibernate4.LocalSessionfactorybean.buildSessionFactory(LocalSessionfactorybean.java:373) at org.springframework.orm.hibernate4.LocalSessionfactorybean.afterPropertiesSet(LocalSessionfactorybean.java:358) at org.springframework.beans.factory.support.AbstractAutowireCapablebeanfactory.invokeInitMethods(AbstractAutowireCapablebeanfactory.java:1571) at org.springframework.beans.factory.support.AbstractAutowireCapablebeanfactory.initializeBean(AbstractAutowireCapablebeanfactory.java:1509) ... 34 more
@OneToOne(targetEntity = MnEditFlag.class,fetch = FetchType.LAZY) @JoinColumn(name = "REFFLG",referencedColumnName = "FLAG_NAME",insertable = false,updatable = false) MnEditFlag mnEditFlag;
Solution
The reason for the problem is that you try to use a single join column, and the identity of the reference entity is defined by multiple columns You just need to define all the required connection columns:
@JoinColumns({ @JoinColumn(name = "REFFLG",referencedColumnName = "FLAG_NAME"),@JoinColumn(name = "OTHER_KEY",referencedColumnName = "SOME_OTHER_NAME")) ... }) MnEditFlag mnEditFlag;
@JoinTable(name="ReferralsM_MnEditFlag",joinColumns={ @JoinColumn(name="REFERRALS_ID1",referencedColumnName="ID1"),@JoinColumn(name="REFERRALS_ID2",referencedColumnName="ID2") },inverseJoinColumns={ @JoinColumn(name="REFFLG",referencedColumnName="FLAG_NAME"),@JoinColumn(name="REFFLG2",referencedColumnName="FLAG_NAME2") }) MnEditFlag mnEditFlag;
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码