-->
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.  [ 3 posts ] 
Author Message
 Post subject: composite-id with a many-to-one relationship.
PostPosted: Sun Sep 28, 2003 6:44 am 
Newbie

Joined: Thu Sep 25, 2003 10:51 am
Posts: 2
Location: Milan, Italy
Sorry guys, but I'm trying to understand the cause of this problem.

The first table (USERS) has very simple structure:
CODE (int) PK
NAME (String)

The second table (DATA) has a more complex structure:
DAY (int) PK
CODE (int) PK
VALUE1 (int) ... VALUEn (int) are the data

there id a one-to-many relationship between the first table and the second table, using CODE as the key.

I have developed the bean of my first table (UserDBean) as a simple bean, with two properties (code is an int and name is a String). The id is assigned (all data comes from daily files).

For the second table (DataDBean) I have developed the bean containing all the values... and, for the primary key, I have used a PrimaryKey bean (DataPKBean) following basic directions.

This DataPKBean contains an int property for the DAY and a UserBean property for the CODE.

The DataDBean xml mapping file, contains something like this:
...
<composite-id name="pk" class="...DataPKBean">
<key-property name="day" type="int"/>
<key-many-to-one name="user" column="code"/>
</composite-id>
...

Now in the code that takes care of importing the file, I first check if the user exists in the user table. If does exist i get the user from the db, if not i create a new user with the code/name values i get from my file.

From the file i also get the day. I then create a new DataPKBean by using the day and the userBean.

Then i create a new DataDBean inserting all the values from the file, and I execute a save(dataDBean, dataPKBean).

And that's the problem...

Error:
identifier of an instance of ...DataDBean altered from [hashcode] to [hashcode].

What is strange is that the two hashcodes are exactly the same...

The question is, where is my error...

Thanks in advance
Regards,
Kazuma


Top
 Profile  
 
 Post subject:
PostPosted: Sun Sep 28, 2003 6:12 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
That is not the hasCode(), it is the toString().

Looks like your equals() method is broken.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 01, 2003 5:09 am 
Newbie

Joined: Thu Sep 25, 2003 10:51 am
Posts: 2
Location: Milan, Italy
gavin wrote:
That is not the hasCode(), it is the toString().
Looks like your equals() method is broken.


Yes, it is the toString() method that is displayed. just a typo.

I also thought the problem was on the equals() method, but i think that that it is correct. The equals in the PK class is very simple: it checks if the two DAYS (int) are equals. If not it returns false, otherwise it checks the two users by using the equals() method of the userBean that works on the pk of that class (that's an int).

Anyway I will recheck both equals() method, hoping that i made another typo in there...

Anyway, other suggestion?


regards,
Kazuma


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

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.