-->
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: need help with mapping problem on difficult datastructure
PostPosted: Thu Jan 04, 2007 6:15 pm 
Newbie

Joined: Thu Jan 04, 2007 5:55 pm
Posts: 4
Hello,

i have a simple Class named Graph which contains:
Code:
   private long id;
   private Set<Node> nodeSet = new HashSet<Node>();
   private Set<Edge> edgeSet = new HashSet<Edge>();

   get... set...


a Class named Edge which contains:
Code:
   private long id;
   private Node from;
   private Node to;
   private String value;

   get... set...


and a Class named Node which contains:
Code:
   private long id;
   private String value = "";

   private Set<Edge> incoming = new HashSet<Edge>();
   private Set<Edge> outgoing = new HashSet<Edge>();

   get... set...


I think i have a problem in understanding the configuration. I read the reference / the examples several times but I dont find a solution to store these Data Structure. I always get errors.

Can someone can give me a hint ?

Thanks,
Ralf

Hibernate version:
3.2.0

Mapping documents:
Node.hbm.xml
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
      "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
      "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
   <class name="de.neologics.network.graph.Node" table="Node">
      <id name="id" column="NODE_ID">
         <generator class="native"/>
      </id>
      <property name="value" column="Value" />

      <set name="incoming" >
         <key column="NODE_ID" />
         <many-to-many column="EDGE_ID" class="de.neologics.network.graph.Edge"/>
      </set>

      <set name="outgoing" >
         <key column="NODE_ID" />
         <many-to-many column="EDGE_ID" class="de.neologics.network.graph.Edge"/>
      </set>
      
   </class>
</hibernate-mapping>



Graph.hbm.xml
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
      "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
      "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
   <class name="de.neologics.network.graph.Graph" table="Graph">
      <id name="id" column="GRAPH_ID">
         <generator class="native"/>
      </id>

      <set name="nodeSet" table="NodeSet" cascade="none" >
         <key column="GRAPH_ID" />
         <many-to-many column="NODE_ID" class="de.neologics.network.graph.Node"/>
      </set>

      <set name="edgeSet" table="EdgeSet" cascade="none">
         <key column="GRAPH_ID" />
         <many-to-many column="EDGE_ID" class="de.neologics.network.graph.Edge"/>
      </set>
      
   </class>
</hibernate-mapping>


Edge.hbm.xml
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
      "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
      "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
   <class name="de.neologics.network.graph.Edge" table="Edge">
      <id name="id" column="EDGE_ID">
         <generator class="native" />
      </id>
      <property name="value" />
      
      <many-to-one name="from"
         column="NODE_ID" insert="false" update="false"
         class="de.neologics.network.graph.Node"/>
      <many-to-one name="to"
         column="NODE_ID" insert="false" update="false"
         class="de.neologics.network.graph.Node"/>

   </class>
</hibernate-mapping>



Code between sessionFactory.openSession() and session.close():
Code:
Graph p_oGraph = is initialized with some data.

session.beginTransaction();

if( true ){  // for test purposes
   for( Edge current  : p_oGraph.getEdgeSet() ){
      System.out.println("current = " + current);
      session.saveOrUpdate( current );
   }
   System.out.println("end edges loop");

   for( Node current  : p_oGraph.getNodeSet() ){
      System.out.println("current = " + current);
      session.saveOrUpdate( current );
   }
   System.out.println("end node loop");
   session.flush();
}   
session.saveOrUpdate( p_oGraph );
session.getTransaction().commit();


Full stack trace of any exception that occurs:
org.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1

Name and version of the database you are using:
MySql 4.1


Top
 Profile  
 
 Post subject: Let's see
PostPosted: Fri Jan 05, 2007 4:23 am 
Beginner
Beginner

Joined: Wed Aug 31, 2005 3:54 am
Posts: 45
To define the relationship between elements you must identify columns that are part of database foreign key constraint.

So for example :
Node must containt the foreign key to defined his Edge father

<hibernate-mapping>
<class name="de.neologics.network.graph.Node" table="Node">
<id name="id" column="NODE_ID">
<generator class="native"/>
</id>
<property name="value" column="Value" />

<set name="incoming" >
<key column="???" /> ==> the column of node table that identify Edge father
<many-to-one column="???" ==> the id column of edge
class="de.neologics.network.graph.Edge"/>
</set>

<set name="outgoing" >
<key column="???" /> ==> the column of node table that identify Edge father
<many-to-one column="???" ==> the id column of edge
class="de.neologics.network.graph.Edge"/>
</set>

</class>
</hibernate-mapping>

Don't forget to rate ... ;-)


Top
 Profile  
 
 Post subject: Re: Let's see
PostPosted: Fri Jan 05, 2007 7:26 am 
Newbie

Joined: Thu Jan 04, 2007 5:55 pm
Posts: 4
Hello,

thanx for your answer, but i found the Problem. I didnt misunderstood. The tables created by Hibernate are created in the right way.
I had a testroutine in which i created a example graph using the property id to detect, whether the node/edge is already in the graph and to determine inconsistency. For that test, I setted the id to a specific value. So it crashed, when i called the save routine.
My solution is, to create unique ids at creation of edge/node and check them against the graph.

Puh, hours of work...

Thanks,
Ralf Heyde


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.