-->
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: primary key is another datatype than the foreign key
PostPosted: Tue Dec 08, 2009 7:00 am 
Newbie

Joined: Thu Jul 17, 2008 10:27 am
Posts: 5
Hi all,

I am new to hibernate and just in the beginning I got a little problem.
We have an old database and in one table the pk is an integer and in the other table the fk is a bigint.

As soon as I am using a OneToMany and ManyToOne relation I got the following exception:
[code]
Caused by: org.hibernate.HibernateException: Wrong column type: refid, expected: integer
at org.hibernate.mapping.Table.validateColumns(Table.java:261)
at org.hibernate.cfg.Configuration.validateSchema(Configuration.java:1083)
at org.hibernate.tool.hbm2ddl.SchemaValidator.validate(SchemaValidator.java:116)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:317)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1294)
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:713)
... 136 more
[/code]

These are the entities:
[code]
@Entity
@Table(name="PERSON")
public class Person {

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name="personId")
private int id;

@ManyToOne
@JoinColumn(name="refid")
private Address address;
}
[/code]

[code]
@Entity
@Table(name = "ADDRESS")
public class Address {

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "addressId")
private int id;

@OneToMany(mappedBy="address")
@Column(name="personId")
private Set<Person> people;
}
[/code]

It would be very nice if someone could help me. By the way, it is not possible to change a column the database :(

Greetings,
arres


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.