-->
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.  [ 2 posts ] 
Author Message
 Post subject: Impossible to set reference to another oject on same table!!
PostPosted: Tue Jan 22, 2008 6:21 am 
Newbie

Joined: Mon Oct 01, 2007 3:39 am
Posts: 11
Hello,

i have a problem with code generate by Reverse engineering.

I have the following table:

ASSISTIBILI, which has

Primary Key : PKASSISTIBILI
Foreign Key: ASSISTIBILI_FK which refers to ASSISTIBILI.PKASSISTIBILI

This is a composite, where each record can have a reference to another record in the same table. the association is *--->1

The generated code contains the following methods:

public Assistibili getAssistibili() {
return this.assistibili;
}

public void setAssistibili(Assistibili assistibili) {
this.assistibili = assistibili;
}


public Set getAssistibilis() {
return this.assistibilis;
}

public void setAssistibilis(Set assistibilis) {
this.assistibilis = assistibilis;
}

And the mapping file contains:

<set name="assistibilis" inverse="true">
<key>
<column name="ASSISTIBILI_FK" precision="9" scale="0" />
</key>
<one-to-many class="com.reveng.Assistibili" />
</set>


Somebody can explain to me why i have the method:

public void setAssistibilis(Set assistibilis) {
this.assistibilis = assistibilis;
}

??

The referred record can be only one!!!!!!
Why can i set a collection of objects?


Anyway, i try to use the code in this way:

Assistibili ass1 = (Assistibili)em.find(Assistibili.class, new Integer(1259));
Assistibili ass2 = (Assistibili)em.find(Assistibili.class, new Integer(1260));

ass1.setAssistibili(ass2);

commit();


After this when i go to see on the database, my foreign Key field is still empty!!!!!
Can i set the referred object in this way??

If not, how should i do?????

Greetings,
Fabio


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 22, 2008 11:10 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
there is nothing in the foreignkey that says it is only a one to one.

_________________
Max
Don't forget to rate


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.