I'm new to Hibernate and maybe my problem is quite simple, but steal I have problems with mapping.
What I want to do is to have two links for different objects from one table.
Lets say I have a Pair and a Person classes. Every Pair can have 1(until second person doesn't connect) or 2 Persons or even more(It would not be a pair then =)). Lets say it could have a set of objects. And I would like a Peson class to have a Pair-class link.
I've thought of having following tables:
person(person_id, pair_id, person_name);
pair(pair_id, ... another pair info);
So this two tables would be joined by pair_id.
I've tryied to map this:
Code:
<class name="Pair" table="pair">
<id name="id" type="long" unsaved-value="null">
<column name="id" sql-type="int(11)" not-null="true"/>
<generator class="native"/>
</id>
<set name="person" table="person">
<key column="pair_id" not-null="true"/>
<one-to-many class="Person"/>
</set>
</class>
<class name="Person" table="person">
<id name="id" type="long" unsaved-value="null">
<column name="id" sql-type="int(11)" not-null="true"/>
<generator class="native"/>
</id>
<property name="name">
<column name="name" sql-type="char(255)" not-null="true"/>
</property>
<one-to-one name="pair" property-ref="person"/>
</class>
When using this mapping I can't save objects
(Person p= new Person();
Set s = new HashSet();
s.add(p);
Pair pair = new Pair();
pair.setPersons(s);
session.save(pair);
)
I receive:
Code:
splayer Error: 500 Location: /fightlistInternal Servlet Error:org.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1
at org.hibernate.jdbc.Expectations$BasicExpectation.checkBatched(Expectations.java:61)
at org.hibernate.jdbc.Expectations$BasicExpectation.verifyOutcome(Expectations.java:46)
at org.hibernate.jdbc.BatchingBatcher.checkRowCounts(BatchingBatcher.java:68)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:246)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:237)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:145)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at org.hibernate.context.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:301)
at $Proxy0.flush(Unknown Source)
at fightclub.FightListServlet.doGet(FightListServlet.java:72)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.tomcat.core.ServletWrapper.doService(ServletWrapper.java:405)
at org.apache.tomcat.core.Handler.service(Handler.java:287)
at org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:372)
at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:812)
at org.apache.tomcat.core.ContextManager.service(ContextManager.java:758)
at org.apache.tomcat.service.http.HttpConnectionHandler.processConnection(HttpConnectionHandler.java:213)
at org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java:416)
at org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java:501)
at java.lang.Thread.run(Thread.java:534)
But when I've manually inserted data into tables, I could read them...
What am I doing wrong?
Thank's for the help!