-->
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.  [ 5 posts ] 
Author Message
 Post subject: many to many supply table problem
PostPosted: Thu Oct 28, 2004 11:54 am 
Newbie

Joined: Thu Oct 28, 2004 11:30 am
Posts: 3
I have a problem with many to many.
Every data geting insert in to the DB but the supply table "PLANET_DBCOMP" is still empty.
I dont know why please help me.

Hibernate version:
hibernate-2.1
Mapping documents:
Not full I hope all you need.

The planet:
<hibernate-mapping>
<class name="ch.galastria.common.Planet" table="PLANET">
<id name="id" column="ID" type="long">
<generator class="assigned" />
</id>
<property name="type" column="TYPE" type="short" />
<property name="name" column="NAME" type="string" />
<many-to-one name="account" column="OWNER" class="ch.galastria.common.Account" cascade="none" />
<set name="dbComponents" table="PLANET_DBCOMP" inverse="true" lazy="true" cascade="all" >
<key column="PLANET_ID" />
<many-to-many class="ch.galastria.common.component.Dbgcomponent" column="DBCOMPONENT_ID" />
</set>
</class>
</hibernate-mapping>

The components:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="ch.galastria.common.component.Dbgcomponent" table="DBGCOMPONENT">
<id name="id" column="INDIVIDUALID" type="int">
<generator class="net.sf.hibernate.id.IncrementGenerator">
</generator>
</id>
<property name="level" column="LEVEL" type="int" />
<property name="objectid" column="OBJECTID" type="string" not-null="true" />
<set name="planets" table="PLANET_DBCOMP" cascade="all" lazy="true">
<key column="DBCOMPONENT_ID" />
<many-to-many class="ch.galastria.common.Planet" column="PLANET_ID"/>
</set>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
List tempPlanetList = session.find("from Planet as pla where id = ?",
planet.getId(),
Hibernate.LONG);
Planet tempPlanet = (Planet)tempPlanetList.get(0);
HashSet resources = new HashSet();
resources.add(new Dbgcomponent()); //not full just for example (also add properties)
Transaction tx = session.beginTransaction();
tempPlanet.setAccount(user);
tempPlanet.setDbComponents(resources);
session.update(tempPlanet);
session.flush();
tx.commit();

Full stack trace of any exception that occurs:
No errors
Name and version of the database you are using:
SAP DB
The generated SQL (show_sql=true):
Hibernate: insert into DBGCOMPONENT (LEVEL, OBJECTID, TYPEID, TIME2FINISH, INDIVIDUALID) values (?, ?, ?, ?, ?)
Hibernate: insert into DBGCPROPERTIES (PROPVALUE, NAME, DBGOBJECT, ID) values (?, ?, ?, ?)
Hibernate: insert into DBGCOMPONENT (LEVEL, OBJECTID, TYPEID, TIME2FINISH, INDIVIDUALID) values (?, ?, ?, ?, ?)
Hibernate: insert into DBGCPROPERTIES (PROPVALUE, NAME, DBGOBJECT, ID) values (?, ?, ?, ?)
Hibernate: insert into DBGCOMPONENT (LEVEL, OBJECTID, TYPEID, TIME2FINISH, INDIVIDUALID) values (?, ?, ?, ?, ?)
Hibernate: insert into DBGCPROPERTIES (PROPVALUE, NAME, DBGOBJECT, ID) values (?, ?, ?, ?)
Hibernate: insert into DBGCOMPONENT (LEVEL, OBJECTID, TYPEID, TIME2FINISH, INDIVIDUALID) values (?, ?, ?, ?, ?)
Hibernate: insert into DBGCPROPERTIES (PROPVALUE, NAME, DBGOBJECT, ID) values (?, ?, ?, ?)
Hibernate: insert into DBGCOMPONENT (LEVEL, OBJECTID, TYPEID, TIME2FINISH, INDIVIDUALID) values (?, ?, ?, ?, ?)
Hibernate: insert into DBGCPROPERTIES (PROPVALUE, NAME, DBGOBJECT, ID) values (?, ?, ?, ?)
Hibernate: insert into DBGCOMPONENT (LEVEL, OBJECTID, TYPEID, TIME2FINISH, INDIVIDUALID) values (?, ?, ?, ?, ?)
Hibernate: insert into DBGCPROPERTIES (PROPVALUE, NAME, DBGOBJECT, ID) values (?, ?, ?, ?)
Hibernate: update PLANET set TYPE=?, NAME=?, OWNER=? where ID=?
Hibernate: update ACCOUNT set DIPLO=?, LASTACTIVE=?, LASTIP=?, LASTLOGIN=?, NAME=?, POINTS=?, STATE=?, USERMESSAGES=?, ALLIANCE=? where ID=?
Hibernate: update PROPERTIES set EMAIL=?, GRAPHICPATH=?, LOCALE=?, NEWMESSAGES=?, GTIMEZONE=?, USERPASSWORD=? where PropertiesID=?
Hibernate: update PLANET set OWNER=null where OWNER=?
Hibernate: update DBGCPROPERTIES set PROPERTIES=? where ID=?
Hibernate: update DBGCPROPERTIES set PROPERTIES=? where ID=?
Hibernate: update DBGCPROPERTIES set PROPERTIES=? where ID=?
Hibernate: update DBGCPROPERTIES set PROPERTIES=? where ID=?
Hibernate: update DBGCPROPERTIES set PROPERTIES=? where ID=?
Hibernate: update DBGCPROPERTIES set PROPERTIES=? where ID=?
Hibernate: update PLANET set OWNER=? where ID=?
Debug level Hibernate log excerpt:
Debug


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 29, 2004 3:21 am 
Newbie

Joined: Thu Oct 28, 2004 11:30 am
Posts: 3
Fogot to post the xml-File of the supply table.

Planet_Dbgcomponent.hbm.xml
Quote:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="ch.galastria.common.component.Planet_Dbgcomponent" table="PLANET_DBCOMP">
<composite-id>
<key-many-to-one name="planets" class="ch.galastria.common.Planet" column="PLANET_ID"/>
<key-many-to-one name="dbComponents" class="ch.galastria.common.component.Dbgcomponent" column="DBCOMPONENT_ID"/>
</composite-id>
</class>
</hibernate-mapping>


I dont undertand why it dosn't work.
Please help me.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 29, 2004 4:52 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
you have a birectionnal associaiton so:
1- check one is marked with inverse=true and the other with inverse= false
2- on your java code, don't use a.getBs().add(b) or remove(b), but a.add(b) which manage both ends of the association

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 29, 2004 6:57 am 
Newbie

Joined: Thu Oct 28, 2004 11:30 am
Posts: 3
Thanks anthony.
Tip 1 I have done but had no effect, think on the components was inverse="false" by default.
Tip 2 Use a.add(b) not a.getBs().add(b) . I think b in fist time is a HashSet and in second time a Object. If this is right I used the first one.
What ever, on that account I tried that both objects have references to another.
That workt.
I tried many things else and last but not least I found my fault.
On many-to-many the objects have to be insert on side witch is not inverse.
Thats it now everything work very well.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 29, 2004 7:15 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
best practice: no matter where is the inverse side, you have to manage your instances, so by doing this, each side is up to date and there is no possible bug
easy

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


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