Hi,
I have a simple example but I can't get through it.
Hibernate version:
3.1.3
The tables:
Code:
USERS
-------------
User_ID [PK]
login
password
and
Code:
CLIENTS
-------------
Client_ID [PK]
User_ID [FK]
name
Mapping documents:Main fragments of .hbm.xml files are
Code:
<class name="Users" table='"USERS"'>
<id name="userid" column='"User_ID"' type="java.lang.Integer">
<generator class="sequence">
<param name="sequence">"USERS_User_ID_seq"</param>
</generator>
</id>
<property name="login" column="login" not-null="true" type="java.lang.String" />
<property name="password" column="password" not-null="true" type="java.lang.String" />
<one-to-one name="client" class="Clients" constrained="false"/>
</class>
and
Code:
<class name="Clients" table='"CLIENTS"'>
<id name="clientid" column='"Client_ID"' type="java.lang.Integer">
<generator class="foreign">
<param name="property">users</param>
</generator>
</id>
<one-to-one name="users" class="Users" constrained="true"/>
<property name="name" column='"name"' type="java.lang.String" not-null="true" />
</class>
Full stack trace of any exception that occurs:
Quote:
org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:63)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:181)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:226)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:136)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:274)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:730)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:324)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:86)
at Clients.saveOrUpdate(Clients.java:53)
at CreatingAction.execute(CreatingAction.java:26)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
at java.lang.Thread.run(Unknown Source)
Caused by: java.sql.BatchUpdateException: Zadanie wsadowe 0 insert into "CLIENTS" ("name", "Client_ID") values (asdf, 23) zostało przerwane. Wywołaj getNextException by poznać przyczynę.
at org.postgresql.jdbc2.AbstractJdbc2Statement$BatchResultHandler.handleError(AbstractJdbc2Statement.java:2512)
at org.postgresql.core.v3.QueryExecutorImpl$1.handleError(QueryExecutorImpl.java:399)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1310)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:347)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeBatch(AbstractJdbc2Statement.java:2574)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:57)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:174)
... 29 more
Name and version of the database you are using:PostgreSQL 8.1.4-1
Debug level Hibernate log excerpt:I've received following:
Quote:
Hibernate: select nextval ('"USERS_User_ID_seq"')
Hibernate: insert into "USERS" (login, password, "User_ID") values (?, ?, ?)
Hibernate: insert into "CLIENTS" ("name", "Client_ID") values (?, ?)
111130 [http-8080-Processor25] WARN org.hibernate.util.JDBCExceptionReporter - SQL Error: 0, SQLState: null
111130 [http-8080-Processor25] ERROR org.hibernate.util.JDBCExceptionReporter - Zadanie wsadowe 0 insert into "CLIENTS" ("name", "Client_ID") values (asdf, 23) zostało przerwane. Wywołaj getNextException by poznać przyczynę.
111130 [http-8080-Processor25] WARN org.hibernate.util.JDBCExceptionReporter - SQL Error: 0, SQLState: 23502
111130 [http-8080-Processor25] ERROR org.hibernate.util.JDBCExceptionReporter - ERROR: null value in column "User_ID" violates not-null constraint
111140 [http-8080-Processor25] ERROR org.hibernate.event.def.AbstractFlushingEventListener - Could not synchronize database state with session
After creating a new user I have a new one in the table USERS but CLIENTS isn't updated. User_ID is "23" like Client_ID in logs mentioned above. I wonder if I made some mistakes in my .hbm.xml files. Can somebody tell me are they properly or do I misunderstand the idea of one-to-one association? Or maybe I should look for mistakes in .java files when I update the db?