-->
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.  [ 1 post ] 
Author Message
 Post subject: Can this be done - joined-subclass question?
PostPosted: Fri Feb 25, 2005 8:48 am 
Newbie

Joined: Wed Dec 15, 2004 10:38 am
Posts: 5
Location: Maidstone, England
Read the rules before posting!
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:2.1

Mapping documents:


Code:
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-mapping
   PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
   "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>

  <class name="uk.police.kent.licensing.shared.Person" table="PERSON">
    <id name="id" column="PERSON_ID"  unsaved-value="0">
         <generator class="sequence">
            <param name="sequence">PERSON_SEQ</param>
         </generator>
    </id>
    <property name="firstName" column="FIRST_NAME" type="string" />
    <property name="lastName" column="LAST_NAME" type="string" />
    <property name="dateOfBirth" column="DATE_OF_BIRTH" type="date" />
    <property name="homeTelephone" column="HOME_TELEPHONE" type="string" />
    <property name="mobileTelephone" column="MOBILE_TELEPHONE" type="string" />
    <property name="email" column="EMAIL" type="string" />
    <property name="nationalInsuranceNumber" column="NATIONAL_INSURANCE" type="string" />
    <property name="title" column="TITLE" type="string" />
    <set name="audits" table="AUDIT" cascade="all" inverse="true" lazy="true">
      <key column="ID" />
      <one-to-many class="uk.police.kent.licensing.shared.PersonAudit" />
    </set>
    <many-to-one name="address" cascade="save-update" column="ADDRESS_ID" class="uk.police.kent.licensing.shared.Address" />
    <joined-subclass name="uk.police.kent.licensing.shared.PremisesLicenceHolderPerson" table="LICENCE_HOLDER">
      <key column="PERSON_ID" />
      <property name="jobTitle" column="JOB_TITLE" type="string" />
      <property name="status" column="STATUS" type="string" />
      <property name="dateEffectiveOn" column="DATE_EFFECTIVE_ON" type="date" />
      <set name="licences" table="LICENCE_LICENCEHOLDER" inverse="true" lazy="true">
        <key column="PERSON_ID" />
        <many-to-many class="uk.police.kent.licensing.shared.Licence" column="LICENCE_ID" />
      </set>
    </joined-subclass>
      <joined-subclass name="uk.police.kent.licensing.shared.PersonalLicenceHolder" table="PERSONAL_LICENCEHOLDER">
         <key column="PERSON_ID" />
         <property name="status" column="STATUS" type="string" />
      <property name="dateEffectiveOn" column="DATE_EFFECTIVE_ON" type="date" />
         <one-to-one name="personalLicence" class="uk.police.kent.licensing.shared.PersonalLicence" property-ref="person" />
         <set name="licences" table="PREMISES_LICENCE" cascade="all" lazy="true">
            <key column="PERSON_ID" />
            <one-to-many class="uk.police.kent.licensing.shared.PremisesLicence" />
         </set>
      </joined-subclass>
  </class>
</hibernate-mapping>


Code:
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-mapping
   PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
   "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
  <class name="uk.police.kent.licensing.shared.Licence" table="LICENCE">
    <id name="id" column="LICENCE_ID" unsaved-value="0">
         <generator class="sequence">
            <param name="sequence">LICENCE_SEQ</param>
         </generator>
    </id>
    <property name="status" column="STATUS" type="string" />
    <property name="dateApplication" column="DATE_APPLICATION" type="date" />
<!--    <set name="audits" table="AUDIT">
      <key column="id" />
      <one-to-many class="uk.police.kent.licensing.shared.Audit" />
    </set> -->
      <joined-subclass name="uk.police.kent.licensing.shared.PersonalLicence" table="PERSONAL_LICENCE">
         <key column="LICENCE_ID" />
         <many-to-one name="person" column="PERSON_ID" class="uk.police.kent.licensing.shared.PersonalLicenceHolder" unique="true" cascade="all" />
      </joined-subclass>

      <joined-subclass name="uk.police.kent.licensing.shared.PremisesLicence" table="PREMISES_LICENCE">
         <key column="PREMLIC_ID" />
         <property name="sameHours" column="SAME_HOURS" type="boolean" />
         <property name="sundayHours" column="SUNDAY_HOURS" type="string" />
         <property name="mondayHours" column="MONDAY_HOURS" type="string" />
         <property name="tuesdayHours" column="TUESDAY_HOURS" type="string" />
         <property name="wednesdayHours" column="WEDNESDAY_HOURS" type="string" />
         <property name="thursdayHours" column="THURSDAY_HOURS" type="string" />
         <property name="fridayHours" column="FRIDAY_HOURS" type="string" />
         <property name="saturdayHours" column="SATURDAY_HOURS" type="string" />
         <property name="generalHours" column="GENERAL_HOURS" type="string" />
         <property name="numberDoorSupervisors" column="NUMBER_DOOR_SUPERVISORS" type="integer" />
         <property name="doorSupervisorComments" column="DOOR_SUPERVISOR_COMMENTS" type="string" />
      <many-to-one name="premises" column="PREMISES_ID" class="uk.police.kent.licensing.shared.Premises" />
         <many-to-one name="dps" column="PERSON_ID" class="uk.police.kent.licensing.shared.PersonalLicenceHolder" />   
      <set name="licensableActivities" table="LICENSABLE_ACTIVITY" lazy="true">
        <key column="PREMLIC_ID" />
        <element column="DESCRIPTION" type="string" />
      </set>
       <set name="conditions" table="CONDITION" cascade="all-delete-orphan" inverse="true"  lazy="true">
        <key column="PREMLIC_ID" />
        <one-to-many class="uk.police.kent.licensing.shared.Condition" />
      </set>
      <set name="licenceesPerson" table="LICENCE_LICENCEHOLDER" cascade="all">
        <key column="LICENCE_ID" />
        <many-to-many class="uk.police.kent.licensing.shared.PremisesLicenceHolderPerson" column="PERSON_ID" />
      </set>
      <set name="licenceesOrganisation" table="LICENCE_LICENCEHOLDER_ORG" cascade="all">
        <key column="LICENCE_ID" />
        <many-to-many class="uk.police.kent.licensing.shared.PremisesLicenceHolderOrganisation" column="ORG_ID" />
      </set>
       <set name="audits" table="AUDIT" cascade="all" inverse="true" lazy="true">
        <key column="ID" />
        <one-to-many class="uk.police.kent.licensing.shared.LicenceAudit" />
      </set>
      </joined-subclass>
  </class>
</hibernate-mapping>


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

Code:
      session = getSessionFactory().openSession();
         tx = session.beginTransaction();
         pl.setPerson(licenceHolder);
         Long personalLicenceId = (Long) session.save(pl);
         tx.commit();
/*         tx = session.beginTransaction();
      session.saveOrUpdate(licenceHolder);
         tx.commit();*/
         tx = session.beginTransaction();
         licence.setDps(licenceHolder);
         session.update(licence);
      tx.commit();


the session is closed in the finally block

Full stack trace of any exception that occurs:

Code:
12:15:02,718  WARN StaleObjectStateException:27 - An operation failed due to stale data

net.sf.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect) for uk.police.kent.licensing.shared.PersonalLicenceHolder instance with identifier: 221

   at net.sf.hibernate.persister.AbstractEntityPersister.check(AbstractEntityPersister.java:514)

   at net.sf.hibernate.persister.NormalizedEntityPersister.update(NormalizedEntityPersister.java:667)

   at net.sf.hibernate.persister.NormalizedEntityPersister.update(NormalizedEntityPersister.java:642)

   at net.sf.hibernate.impl.ScheduledUpdate.execute(ScheduledUpdate.java:52)

   at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2438)

   at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2392)

   at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2260)

   at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:61)

   at uk.police.kent.licensing.shared.data.LicenceHolderDAO.saveNewLicenceHolder(LicenceHolderDAO.java:91)

   at uk.police.kent.licensing.web.LicenceHolderAction.saveEditPH(LicenceHolderAction.java:130)

   at uk.police.kent.licensing.web.LicenceHolderAction.save(LicenceHolderAction.java:45)

   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.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:280)

   at org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:216)

   at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)

   at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)

   at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)

   at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)

   at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)

   at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)

   at com.evermind.server.http.ResourceFilterChain.doFilter(ResourceFilterChain.java:65)

   at oracle.security.jazn.oc4j.JAZNFilter.doFilter(Unknown Source)

   at com.evermind.server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:604)

   at com.evermind.server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:317)

   at com.evermind.server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:790)

   at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:270)

   at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:112)

   at com.evermind.util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:186)

   at java.lang.Thread.run(Thread.java:534)

12:15:02,734 ERROR SessionImpl:2399 - Could not synchronize database state with session

05/02/25 12:15:06 uk.police.kent.licensing.shared.data.DataAccessException: Error loading or saving data...Root cause......
Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect) for uk.police.kent.licensing.shared.PersonalLicenceHolder instance with identifier: 221

05/02/25 12:15:06    at uk.police.kent.licensing.shared.data.LicenceHolderDAO.saveNewLicenceHolder(LicenceHolderDAO.java:107)

05/02/25 12:15:06    at uk.police.kent.licensing.web.LicenceHolderAction.saveEditPH(LicenceHolderAction.java:130)

05/02/25 12:15:06    at uk.police.kent.licensing.web.LicenceHolderAction.save(LicenceHolderAction.java:45)

05/02/25 12:15:06    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

05/02/25 12:15:06    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

05/02/25 12:15:06    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

05/02/25 12:15:06    at java.lang.reflect.Method.invoke(Method.java:324)

05/02/25 12:15:06    at org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:280)

05/02/25 12:15:06    at org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:216)

05/02/25 12:15:06    at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)

05/02/25 12:15:06    at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)

05/02/25 12:15:06    at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)

05/02/25 12:15:06    at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)

05/02/25 12:15:06    at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)

05/02/25 12:15:06    at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)

05/02/25 12:15:06    at com.evermind.server.http.ResourceFilterChain.doFilter(ResourceFilterChain.java:65)

05/02/25 12:15:06    at oracle.security.jazn.oc4j.JAZNFilter.doFilter(Unknown Source)

05/02/25 12:15:06    at com.evermind.server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:604)

05/02/25 12:15:06    at com.evermind.server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:317)

05/02/25 12:15:06    at com.evermind.server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:790)

05/02/25 12:15:06    at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:270)

05/02/25 12:15:06    at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:112)

05/02/25 12:15:06    at com.evermind.util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:186)

05/02/25 12:15:06    at java.lang.Thread.run(Thread.java:534)



Name and version of the database you are using:Oracle 10g

The generated SQL (show_sql=true):

Quote:
12:24:48,984 DEBUG SQL:229 - select LICENCE_SEQ.nextval from dual

05/02/25 12:24:48 Hibernate: select LICENCE_SEQ.nextval from dual

12:24:49,000 DEBUG SQL:229 - insert into LICENCE (STATUS, DATE_APPLICATION, LICENCE_ID) values (?, ?, ?)

05/02/25 12:24:49 Hibernate: insert into LICENCE (STATUS, DATE_APPLICATION, LICENCE_ID) values (?, ?, ?)

12:24:49,000 DEBUG SQL:229 - insert into PERSONAL_LICENCE (PERSON_ID, LICENCE_ID) values (?, ?)

05/02/25 12:24:49 Hibernate: insert into PERSONAL_LICENCE (PERSON_ID, LICENCE_ID) values (?, ?)

12:24:49,000 DEBUG StringType:41 - binding null to parameter: 1

12:24:49,015 DEBUG DateType:41 - binding null to parameter: 2

12:24:49,015 DEBUG LongType:46 - binding '265' to parameter: 3

12:24:49,015 DEBUG LongType:46 - binding '221' to parameter: 1

12:24:49,015 DEBUG LongType:46 - binding '265' to parameter: 2

12:24:49,031 DEBUG SQL:229 - update PERSON set FIRST_NAME=?, LAST_NAME=?, DATE_OF_BIRTH=?, HOME_TELEPHONE=?, MOBILE_TELEPHONE=?, EMAIL=?, NATIONAL_INSURANCE=?, TITLE=?, ADDRESS_ID=? where PERSON_ID=?

05/02/25 12:24:49 Hibernate: update PERSON set FIRST_NAME=?, LAST_NAME=?, DATE_OF_BIRTH=?, HOME_TELEPHONE=?, MOBILE_TELEPHONE=?, EMAIL=?, NATIONAL_INSURANCE=?, TITLE=?, ADDRESS_ID=? where PERSON_ID=?

12:24:49,031 DEBUG SQL:229 - update PERSONAL_LICENCEHOLDER set STATUS=?, DATE_EFFECTIVE_ON=? where PERSON_ID=?

05/02/25 12:24:49 Hibernate: update PERSONAL_LICENCEHOLDER set STATUS=?, DATE_EFFECTIVE_ON=? where PERSON_ID=?

12:24:49,031 DEBUG StringType:46 - binding 'Juan' to parameter: 1

12:24:49,046 DEBUG StringType:46 - binding 'Kerr' to parameter: 2

12:24:49,046 DEBUG DateType:46 - binding '04 September 1965' to parameter: 3

12:24:49,046 DEBUG StringType:46 - binding '012345 65987' to parameter: 4

12:24:49,046 DEBUG StringType:46 - binding '07895422123' to parameter: 5

12:24:49,046 DEBUG StringType:46 - binding 'ju@n.kerr.com' to parameter: 6

12:24:49,046 DEBUG StringType:46 - binding '' to parameter: 7

12:24:49,046 DEBUG StringType:46 - binding 'Mr' to parameter: 8

12:24:49,046 DEBUG LongType:41 - binding null to parameter: 9

12:24:49,046 DEBUG LongType:46 - binding '221' to parameter: 10

12:24:49,046 DEBUG StringType:46 - binding 'Application' to parameter: 1

12:24:49,062 DEBUG DateType:46 - binding '21 February 2005' to parameter: 2

12:24:49,093 DEBUG LongType:46 - binding '221' to parameter: 3


Debug level Hibernate log excerpt:

My issue is this - obviously what I am doing isn't working so have been trying to figure this out for a couple of days now but need clarification as to whether this is possible.

If I already have persisted a object of type PremisesLicenceHolder (that is a sub class of Person and therefore has a Person record also persisted with same ID), and then want to save a different object PersonalLicenceHolder (which is also a subclass of Person) that is also the same person as the first one - i.e. the PersonalLicenceHOlder id should be the same as the Person (and PremisesLicenceHolder) - can this be done??? If so, can anyone suggest any pointers from the above stack trace/ mapping files/ sql etc. ???

Thanks
Conrad


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.