-->
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.  [ 1 post ] 
Author Message
 Post subject: org.hibernate.MappingException: Foreign key must have same n
PostPosted: Thu Sep 19, 2013 7:30 am 
Newbie

Joined: Thu Sep 19, 2013 7:01 am
Posts: 1
Why am I getting this following exception in my hibernate application.

Code:
Caused by: org.hibernate.MappingException: Foreign key (FK2C47CFCAB95CF1D: EMP [ADDR_ID,ADDR_ZIP])) must have same number of columns as the referenced primary key (ADDRESS [ID_COL])
    at org.hibernate.mapping.ForeignKey.alignColumns(ForeignKey.java:110)
    at org.hibernate.mapping.ForeignKey.alignColumns(ForeignKey.java:93)
    at org.hibernate.cfg.Configuration.secondPassCompileForeignKeys(Configuration.java:1714)
    at org.hibernate.cfg.Configuration.originalSecondPassCompile(Configuration.java:1637)
    at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1350)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1737)
    at org.hibernate.ejb.EntityManagerFactoryImpl.<init>(EntityManagerFactoryImpl.java:94)
    at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:920)
    ... 9 more



For my mapping

Code:
@ManyToOne
@JoinColumns({
    @JoinColumn(name="ADDR_ID", referencedColumnName="ID"),
    @JoinColumn(name="ADDR_ZIP", referencedColumnName="ZIP")
})
@NotFound(action=NotFoundAction.IGNORE)
private AddressEntity addressEntity;

My AddressEntity looks as follows

Code:
public AddressEntity {
    @Id
    @Column(name = "ITEM")
    private String item;

    @Column(name = "ADDR_ID")
    private String ID;

    @Column(name = "ADDR_ZIP")
    private String ZIP;

    ...
    ...

}

JoinColumn need not to point to a primary key. But still the exception occurs


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.