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.  [ 2 posts ] 
Author Message
 Post subject: key id is NULL when creating a one-to-one association end
PostPosted: Thu Feb 07, 2008 5:25 am 
Newbie

Joined: Thu Feb 07, 2008 3:56 am
Posts: 1
Hallo,

I'm experiencing this kind of problem on the scenario described below. I've got a relational table with two one-to-one associations. I try to create new records to fullfill a new relation; association end beans are correctly "persisted" from hibernate. Relational table bean won't commit because of one of the foreing key received by Oracle is null (while Hibernate correctly auto generates them with the incremental property setted. Debug inspection shows that relationa table bean is well constructed with no NULL values just befor becoming persistent in the model) . Can you suggest me what's wrong with my code or mappings?

Thanks in advance. Best Regards.

Simone

Hibernate version:

3.2.5ga (core)

Mapping documents:
First end mapping
Code:
<hibernate-mapping package="**********.hibernate.model">
<class name="User" table="VTUC_USER">
  <id column="vtuc_user_id" name="vtuc_user_id">
   <generator class="increment"/>
  </id>
  <property generated="never" lazy="false" name="vtuc_user_username"/>
  <property generated="never" lazy="false" name="vtuc_user_password"/>
  <property generated="never" lazy="false" name="vtuc_date_last_user_login" type="calendar"/>
  <property generated="never" lazy="false" name="vtuc_date_startuser" type="calendar"/>
  <property generated="never" lazy="false" name="vtuc_date_finishuser" type="calendar"/>
  <property generated="never" lazy="false"
   name="vtuc_date_startpassword" type="calendar"/>
  <property generated="never" lazy="false"
   name="vtuc_date_finishpassword" type="calendar"/>
  <many-to-one class="Customer" column="vtuc_customer_id" lazy="false"
   name="customer" not-null="true"/>
  <many-to-one class="Profile" column="vtuc_profile_id" lazy="false" name="profile"/>
  <many-to-one class="StatePassword" column="vtuc_statepassword_id"
   lazy="false" name="statePassword" not-null="true"/>
  <one-to-one class="ContactUser" constrained="true" name="contactUser" property-ref="vtud_user_id" lazy="false"/>
  <many-to-one class="StateUser" column="vtuc_stateuser_id" lazy="false"
   name="stateUser" not-null="true"/>
  <set name="serviceConsistencySet" sort="unsorted">
   <key column="vtue_user_id"/>
   <one-to-many class="ServiceConsistency"/>
  </set>
</class>
</hibernate-mapping>


Second end mapping
Code:
<hibernate-mapping package="********.hibernate.model">
<class name="ServiceConsistency" table="VTUE_SERVICE_CONSISTENCY">
  <id column="vtue_service_consistency_id" name="vtue_service_consistency_id">
   <generator class="increment"/>
  </id>
  <property generated="never" lazy="false" length="250"
   name="vtue_service_consist_vin" not-null="true" type="string"/>
  <property generated="never" lazy="false" length="250"
   name="vtue_service_consistency_obu" not-null="true" type="string"/>
  <one-to-one class="User" name="user"/>
</class>
</hibernate-mapping>

Relational table mapping:
Code:
<hibernate-mapping package="*******.hibernate.model">
<class name="UserServiceConsistency" table="VTUF_USER_SERVICE_CONSISTENCY">
  <id column="vtuf_user_service_consist_id" name="vtuf_user_service_consist_id">
   <generator class="increment"/>
  </id>
  <property generated="never" lazy="false" name="vtuf_user_id"/>
  <one-to-one cascade="all" class="User" name="user"/>
  <one-to-one cascade="all"
   class="********.hibernate.model.ServiceConsistency" name="serviceConsistency"/>
</class>
</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():

Code:
try {
         
         session = HibernateConnectionManager.getSession();
         HibernateConnectionManager.startTransaction(session);

         
         //SOME CODE CUTTED FOR POST
                       //** = cutted for privacy reasons
         
         
         for (int i=0; i<3; i++){
            
            //get input data from view layer
            
            String userNameToCreateString =
               (String)((DynaActionForm) form).get(
                  ****.Constants.FORM_RESOURCE_NEW_NAME+i);
            
            String userSurnameToCreateString =
               (String)((DynaActionForm) form).get(
                  ****.Constants.FORM_RESOURCE_NEW_SURNAME+i);
            
            String userEmailToCreateString =
               (String)((DynaActionForm) form).get(
                  ****.Constants.FORM_RESOURCE_NEW_EMAIL+i);
            
            String userPhoneToCreateString =
               (String)((DynaActionForm) form).get(
                  ****.Constants.FORM_RESOURCE_NEW_PHONE+i);
               
            String userAddressToCreateString =
                  (String)((DynaActionForm) form).get(
                        ****.Constants.FORM_RESOURCE_NEW_ADDRESS+i);
            
            String vinToCreateString =
                  (String)((DynaActionForm) form).get(
                     ****.Constants.FORM_RESOURCE_VIN);
            
            String idObuToCreateString =
               (String)((DynaActionForm) form).get(
                     ****.Constants.FORM_RESOURCE_ID_OBU);
                  
            //CUTTED: Retrive some data from outside logic
            
            //necessary business logic workflow

            newUserObject =
               new User();
            
            newContactUserOfUserObject =
               new ContactUser();
            
            newServiceConsistencyObject =
               new ServiceConsistency();
            
            newUserServiceConsistencyObject =
               new UserServiceConsistency();
            
            //
            
            newContactUserOfUserObject.setVtud_email(
               userEmailToCreateString);
            
            newContactUserOfUserObject.setVtud_phone(
               userPhoneToCreateString);
            
            newContactUserOfUserObject.setVtud_name(
               userNameToCreateString);
            
            newContactUserOfUserObject.setVtud_surname(
               userSurnameToCreateString);
               
            newContactUserOfUserObject.setVtud_address(
                  userAddressToCreateString);

            //
            
            newUserObject.setVtuc_user_username(
               newUserUsername);
            
            newUserObject.setVtuc_user_password(
               newUserPassword);
            
            newUserObject.setVtuc_date_startuser(
               currentCalendar);
            
            newUserObject.setVtuc_date_startpassword(
               currentCalendar);
            
            newUserObject.setVtuc_date_finishpassword(
               threeMonthLaterCalendar);
            
            newUserObject.setContactUser(
                  newContactUserOfUserObject);
            
            newUserObject.setCustomer(
               loggedUserObject.getCustomer());
      
            newUserObject.setProfile(
               profileObject);
            
            newUserObject.setStatePassword(
               statePasswordNewObject);
            
            newUserObject.setStateUser(
               stateUserActiveObject);
            
            newContactUserOfUserObject.setVtud_user_id(
                  newUserObject.getVtuc_user_id());
            
            //
            newServiceConsistencyObject.setVtue_service_consist_vin(
                  vinToCreateString);
            newServiceConsistencyObject.setVtue_service_consistency_obu(
                  idObuToCreateString);
            //
            newUserServiceConsistencyObject.setUser(
                  newUserObject);
            
            newUserServiceConsistencyObject.setServiceConsistency(
                  newServiceConsistencyObject);   
            
            
            //notify to Hibernate persistent layer the updated relation
            session.persist(newUserObject);
            newContactUserOfUserObject.setVtud_user_id(
                  newUserObject.getVtuc_user_id());
            session.persist(newContactUserOfUserObject);
            session.persist(newServiceConsistencyObject);
                                session.persist(newUserServiceConsistencyObject);
      
         }
         
         //try to save persistent layer modification
         
         session.flush();
         HibernateConnectionManager.commitTransaction(session);
         result = true;
         
      }


Full stack trace of any exception that occurs:

10:16:04,438 WARN [JDBCExceptionReporter] SQL Error: 1400, SQLState: 23000
10:16:04,439 ERROR [JDBCExceptionReporter] ORA-01400: cannot insert NULL into ("VT_WA"."VTUF_USER_SERVICE_CONSISTENCY"."VTUF_SERVICE_CONSISTENCY_ID")

10:16:04,440 WARN [JDBCExceptionReporter] SQL Error: 1400, SQLState: 23000
10:16:04,440 ERROR [JDBCExceptionReporter] ORA-01400: cannot insert NULL into ("VT_WA"."VTUF_USER_SERVICE_CONSISTENCY"."VTUF_SERVICE_CONSISTENCY_ID")

10:16:04,441 ERROR [AbstractFlushingEventListener] Could not synchronize database state with session
org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:71)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:253)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:237)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:141)
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 *****.model.MultiUserCreationModel.executePersistentLayer(MultiUserCreationModel.java:388)
at *****.action.obu.InstallOBUAction.myexecute(InstallOBUAction.java:157)
at *****.action.common.SimpleCommonAction.execute(SimpleCommonAction.java:61)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:425)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:228)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
at *****.action.ActionServlet.process(ActionServlet.java:71)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:432)
at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
at java.lang.Thread.run(Thread.java:595)
Caused by: java.sql.BatchUpdateException: ORA-01400: cannot insert NULL into ("VT_WA"."VTUF_USER_SERVICE_CONSISTENCY"."VTUF_SERVICE_CONSISTENCY_ID")

at oracle.jdbc.driver.DatabaseError.throwBatchUpdateException(DatabaseError.java:367)
at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:9118)
at org.jboss.resource.adapter.jdbc.WrappedStatement.executeBatch(WrappedStatement.java:519)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:246)
... 34 more
10:16:04,455 ERROR [GenericLogInterface] Could not execute JDBC batch update
10:16:04,455 ERROR [GenericLogInterface] Could not execute JDBC batch update

Name and version of the database you are using:

Oracle 10G

The generated SQL (show_sql=true):

10:16:04,252 INFO [STDOUT] Hibernate: insert into VTUC_USER (vtuc_user_username, vtuc_user_password, vtuc_date_last_user_login, vtuc_date_startuser, vtuc_date_finishuser, vtuc_date_startpassword, vtuc_date_finishpassword, vtuc_customer_id, vtuc_profile_id, vtuc_statepassword_id, vtuc_stateuser_id, vtuc_user_id) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
10:16:04,296 INFO [STDOUT] Hibernate: insert into vtud_contact_user (vtud_user_id, vtud_name, vtud_surname, vtud_email, vtud_phone, vtud_cell, vtud_address, vtud_contact_user_id) values (?, ?, ?, ?, ?, ?, ?, ?)
10:16:04,326 INFO [STDOUT] Hibernate: insert into VTUE_SERVICE_CONSISTENCY (vtue_service_consist_vin, vtue_service_consistency_obu, vtue_service_consistency_id) values (?, ?, ?)
10:16:04,350 INFO [STDOUT] Hibernate: insert into VTUF_USER_SERVICE_CONSISTENCY (vtuf_user_id, vtuf_user_service_consist_id) values (?, ?)

Debug level Hibernate log excerpt:

2008-02-07 10:16:04,249 org.hibernate.jdbc.AbstractBatcher log DEBUG: about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
2008-02-07 10:16:04,250 org.hibernate.jdbc.ConnectionManager log DEBUG: opening JDBC connection
2008-02-07 10:16:04,251 org.hibernate.jdbc.AbstractBatcher log DEBUG: insert into VTUC_USER (vtuc_user_username, vtuc_user_password, vtuc_date_last_user_login, vtuc_date_startuser, vtuc_date_finishuser, vtuc_date_startpassword, vtuc_date_finishpassword, vtuc_customer_id, vtuc_profile_id, vtuc_statepassword_id, vtuc_stateuser_id, vtuc_user_id) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
2008-02-07 10:16:04,253 org.hibernate.jdbc.BatchingBatcher log DEBUG: Executing batch size: 1
2008-02-07 10:16:04,285 org.hibernate.jdbc.Expectations$BasicExpectation log DEBUG: success of batch update unknown: 0
2008-02-07 10:16:04,292 org.hibernate.jdbc.AbstractBatcher log DEBUG: about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
2008-02-07 10:16:04,294 org.hibernate.jdbc.ConnectionManager log DEBUG: skipping aggressive-release due to flush cycle
2008-02-07 10:16:04,294 org.hibernate.jdbc.AbstractBatcher log DEBUG: about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
2008-02-07 10:16:04,295 org.hibernate.jdbc.AbstractBatcher log DEBUG: insert into vtud_contact_user (vtud_user_id, vtud_name, vtud_surname, vtud_email, vtud_phone, vtud_cell, vtud_address, vtud_contact_user_id) values (?, ?, ?, ?, ?, ?, ?, ?)
2008-02-07 10:16:04,298 org.hibernate.jdbc.BatchingBatcher log DEBUG: Executing batch size: 1
2008-02-07 10:16:04,323 org.hibernate.jdbc.Expectations$BasicExpectation log DEBUG: success of batch update unknown: 0
2008-02-07 10:16:04,324 org.hibernate.jdbc.AbstractBatcher log DEBUG: about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
2008-02-07 10:16:04,324 org.hibernate.jdbc.ConnectionManager log DEBUG: skipping aggressive-release due to flush cycle
2008-02-07 10:16:04,325 org.hibernate.jdbc.AbstractBatcher log DEBUG: about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
2008-02-07 10:16:04,325 org.hibernate.jdbc.AbstractBatcher log DEBUG: insert into VTUE_SERVICE_CONSISTENCY (vtue_service_consist_vin, vtue_service_consistency_obu, vtue_service_consistency_id) values (?, ?, ?)
2008-02-07 10:16:04,326 org.hibernate.jdbc.BatchingBatcher log DEBUG: Executing batch size: 1
2008-02-07 10:16:04,343 org.hibernate.jdbc.Expectations$BasicExpectation log DEBUG: success of batch update unknown: 0
2008-02-07 10:16:04,346 org.hibernate.jdbc.AbstractBatcher log DEBUG: about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
2008-02-07 10:16:04,348 org.hibernate.jdbc.ConnectionManager log DEBUG: skipping aggressive-release due to flush cycle
2008-02-07 10:16:04,348 org.hibernate.jdbc.AbstractBatcher log DEBUG: about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
2008-02-07 10:16:04,349 org.hibernate.jdbc.AbstractBatcher log DEBUG: insert into VTUF_USER_SERVICE_CONSISTENCY (vtuf_user_id, vtuf_user_service_consist_id) values (?, ?)
2008-02-07 10:16:04,350 org.hibernate.jdbc.BatchingBatcher log DEBUG: Executing batch size: 1
2008-02-07 10:16:04,425 org.hibernate.jdbc.AbstractBatcher log DEBUG: about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
2008-02-07 10:16:04,432 org.hibernate.jdbc.ConnectionManager log DEBUG: skipping aggressive-release due to flush cycle
2008-02-07 10:16:04,434 org.hibernate.util.JDBCExceptionReporter log DEBUG: Could not execute JDBC batch update [insert into VTUF_USER_SERVICE_CONSISTENCY (vtuf_user_id, vtuf_user_service_consist_id) values (?, ?)]
java.sql.BatchUpdateException: ORA-01400: cannot insert NULL into ("VT_WA"."VTUF_USER_SERVICE_CONSISTENCY"."VTUF_SERVICE_CONSISTENCY_ID")


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 07, 2008 11:15 am 
Beginner
Beginner

Joined: Mon Mar 07, 2005 6:23 pm
Posts: 21
I believe your problem is that your relationship isn't actually a one-to-one mapping.

If it was, the PK on VTUE_SERVICE_CONSISTENCY and VTUF_USER_SERVICE_CONSISTENCY would be vtuc_user_id, inherited from VTUC_USER

As it stands, you should just treat the relationship as a many-to-one/one-to-many


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