-->
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: v3.5.2 x v4.2.2 => wrong primary key error
PostPosted: Thu Jun 20, 2013 5:36 pm 
Newbie

Joined: Fri Dec 04, 2009 4:17 pm
Posts: 18
I had a legacy database with 2 tables and a relashionship:
- NOTA (PK 3 fields = CODFORNECEDOR/NUMERO/SERIE)
- ITEMNOTA (PK 1 field = CODITEMNOTA, FK not specified in the database, but fields CODFORNECEDOR/NUMERO/SERIE in this table)

Then, after some years, it were created fields:
- NOTA.CODNOTA: just a field, not defined like PK, but it is a auto-increment field in this table
- ITEMNOTA.CODNOTA: just a field, no FK explicity

Then, the entities became like these:

Quote:
@Entity
@SequenceGenerator(name = "CODNOTA_GEN", sequenceName = "CODNOTA_GEN")
@DynamicUpdate
public class Nota implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO, generator="CODNOTA_GEN")
private Long codNota;
...
}

@Entity
@SequenceGenerator(name = "CODITNOTA_GEN", sequenceName = "CODITNOTA_GEN")
@DynamicUpdate
public class ItemNota implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO, generator="CODITNOTA_GEN")
private Long codItemNota;
@ManyToOne
@JoinColumn(name = "CODNOTA", nullable = true)
private Nota nota;
...
}


Using Hibernate 3.5.2 + GlassFish 3.1.1 in a web/enterprise app, it never had problems.
Then, after upgrade to Hibernate 4.2.2 in the last week, it started to arise this error
when deploying the webapp:

Quote:
org.hibernate.MappingException:
Foreign key (FK_f03om5m4q04bbs42wunpha4r7:ITEMNOTA [codNota]))
must have same number of columns as the referenced primary key
(NOTA [CODFORNECEDOR,NUMERONOTA,serie])


Sometimes, after 2/3 attempts to redeploy the webapp, all works fine, GlassFish deploys
and runs the webapp without problems.

What do I have to do to explain for Hibernate 4.2.2 that it must ignore the "oficial"
NOTA PK and just look at NOTA.CODNOTA x ITEMNOTA.CODNOTA to define the relationship?


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.