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.xmlCode:
<?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.xmlCode:
<?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.xmlCode:
<?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