-->
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.  [ 6 posts ] 
Author Message
 Post subject: Converting a persisted object to an instance of a subclass
PostPosted: Tue Feb 28, 2006 6:44 am 
Newbie

Joined: Tue May 24, 2005 7:08 pm
Posts: 17
Location: Melbourne
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 3.1.2

Mapping documents:

Code:
<?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 package="au.com.groupware.profilemanager.model">

   <class name="au.com.groupware.profilemanager.model.Person" table="PERSON">

      <id name="id" column="PERSON_ID" type="integer" unsaved-value="null">
         <generator class="native" />
      </id>

      <property name="firstName" column="FIRST_NAME" type="string" not-null="true" length="100" />
      <property name="lastName" column="LAST_NAME" type="string" not-null="true" length="100" />

      <property name="email" column="EMAIL" type="string" not-null="true" length="255" />
      <property name="phone" column="PHONE" type="string" length="20" />
      <property name="mobile" column="MOBILE" type="string" length="20" />
      <property name="fax" column="FAX" type="string" length="20" />

      <component name="address" class="au.com.groupware.profilemanager.model.Address">
         <property name="streetAddress1" type="string" column="STREET_ADDRESS_1" />
         <property name="streetAddress2" type="string" column="STREET_ADDRESS_2" />
         <property name="city" type="string" column="CITY" />
         <property name="postcode" type="string" column="POSTCODE" />
         <many-to-one name="state" class="au.com.groupware.profilemanager.model.State" column="STATE_ID" not-null="false" />
      </component>
      
      <set name="organisationPeople" table="ORGANISATION_PERSON" lazy="true" cascade="delete-orphan" inverse="true">
            <key column="PERSON_ID" />
            <one-to-many class="au.com.groupware.profilemanager.model.OrganisationPerson" />
         </set>

      <joined-subclass name="au.com.groupware.profilemanager.model.User" table="USERS">

         <key column="USER_ID" />
         <property name="userName" column="USER_NAME" type="string" not-null="true" length="50" unique="true" />
         <property name="password" column="PASSWORD" type="string" not-null="true" length="50" />
         <property name="enabled" column="ENABLED" type="boolean" not-null="true" />

         <set name="organisationsOwned" table="ORGANISATIONS" lazy="true" cascade="save-update" inverse="true">
            <key column="USER_ID" />
            <one-to-many class="au.com.groupware.profilemanager.model.Organisation" />
         </set>

         <set name="userRoles" table="USER_ROLE" lazy="true" cascade="all-delete-orphan" inverse="true">
            <key column="USER_ID" />
            <one-to-many class="au.com.groupware.profilemanager.model.UserRole" />
         </set>

         <set name="groupUsers" table="GROUP_USER" lazy="true" cascade="delete-orphan" inverse="true">
            <key column="USER_ID" />
            <one-to-many class="au.com.groupware.profilemanager.model.GroupUser" />
         </set>

         <set name="applicationAdministrators" table="APPLICATION_ADMINISTRATOR" lazy="true" cascade="none" inverse="true">
            <key column="USER_ID" />
            <one-to-many class="au.com.groupware.profilemanager.model.ApplicationAdministrator" />
         </set>

         <set name="organisationAdministrators" table="ORGANISATION_ADMINISTRATOR" lazy="true" cascade="none" inverse="true">
            <key column="USER_ID" />
            <one-to-many class="au.com.groupware.profilemanager.model.OrganisationAdministrator" />
         </set>

         <set name="groupAdministrators" table="GROUP_ADMINISTRATOR" lazy="true" cascade="none" inverse="true">
            <key column="USER_ID" />
            <one-to-many class="au.com.groupware.profilemanager.model.GroupAdministrator" />
         </set>

         <set name="passwordHistories" table="PASSWORD_HISTORY" lazy="true" cascade="all-delete-orphan" inverse="true">
            <key column="USER_ID" />
            <one-to-many class="au.com.groupware.profilemanager.model.PasswordHistory" />
         </set>

         <set name="requestsAsRequestor" table="REQUEST" lazy="true" cascade="save-update" inverse="true">
            <key column="REQUESTOR_ID" />
            <one-to-many class="au.com.groupware.profilemanager.model.Request" />
         </set>

         <set name="requestsAsActioner" table="REQUEST" lazy="true" cascade="save-update" inverse="true">
            <key column="ACTIONER_ID" />
            <one-to-many class="au.com.groupware.profilemanager.model.Request" />
         </set>

         <set name="requestsAsRequestorToProcess" table="REQUEST" lazy="true" cascade="save-update" inverse="true">
            <key column="USER_ID" />
            <one-to-many class="au.com.groupware.profilemanager.model.Request" />
         </set>
      </joined-subclass>

   </class>

</hibernate-mapping>



The generated SQL (show_sql=true):
Code:
DEBUG - UserDetailsServiceHibernate.loadUserByUsername(51) | loading user with userId 'Test Username 2'
DEBUG - UserManagerImpl.getUserForAuthentication(192) | getting user for authentication with id 'Test Username 2'
Hibernate: select this_.USER_ID as PERSON1_52_0_, this_1_.FIRST_NAME as FIRST2_52_0_, this_1_.LAST_NAME as LAST3_52_0_, this_1_.EMAIL as EMAIL52_0_, this_1_.PHONE as PHONE52_0_, this_1_.MOBILE as MOBILE52_0_, this_1_.FAX as FAX52_0_, this_1_.STREET_ADDRESS_1 as STREET8_52_0_, this_1_.STREET_ADDRESS_2 as STREET9_52_0_, this_1_.CITY as CITY52_0_, this_1_.POSTCODE as POSTCODE52_0_, this_1_.STATE_ID as STATE12_52_0_, this_.USER_NAME as USER2_53_0_, this_.PASSWORD as PASSWORD53_0_, this_.ENABLED as ENABLED53_0_ from USERS this_ inner join PERSON this_1_ on this_.USER_ID=this_1_.PERSON_ID where this_.USER_NAME=?
Hibernate: select this_.USER_ID as PERSON1_52_0_, this_1_.FIRST_NAME as FIRST2_52_0_, this_1_.LAST_NAME as LAST3_52_0_, this_1_.EMAIL as EMAIL52_0_, this_1_.PHONE as PHONE52_0_, this_1_.MOBILE as MOBILE52_0_, this_1_.FAX as FAX52_0_, this_1_.STREET_ADDRESS_1 as STREET8_52_0_, this_1_.STREET_ADDRESS_2 as STREET9_52_0_, this_1_.CITY as CITY52_0_, this_1_.POSTCODE as POSTCODE52_0_, this_1_.STATE_ID as STATE12_52_0_, this_.USER_NAME as USER2_53_0_, this_.PASSWORD as PASSWORD53_0_, this_.ENABLED as ENABLED53_0_ from USERS this_ inner join PERSON this_1_ on this_.USER_ID=this_1_.PERSON_ID where this_.USER_NAME=?
DEBUG - RoleManagerImpl.getCompleteRoleSetForUser(148) | getting complete role set for user with id '2'
Hibernate: select this_.ORGANISATION_ID as ORGANISA1_66_3_, this_.ORGANISATION_NAME as ORGANISA2_66_3_, this_.ABN as ABN66_3_, this_.WEBSITE_URL as WEBSITE4_66_3_, this_.ENABLED as ENABLED66_3_, this_.STREET_ADDRESS_1 as STREET6_66_3_, this_.STREET_ADDRESS_2 as STREET7_66_3_, this_.CITY as CITY66_3_, this_.POSTCODE as POSTCODE66_3_, this_.STATE_ID as STATE10_66_3_, this_.ORG_OWNER_USER_ID as ORG11_66_3_, this_.ORGANISATION_SUB_TYPE_ID as ORGANIS12_66_3_, organisati1_.ORGANISATION_PERSON_ID as ORGANISA1_70_0_, organisati1_.ORGANISATION_ID as ORGANISA2_70_0_, organisati1_.PERSON_ID as PERSON3_70_0_, organisati1_.DATE_MODIFIED as DATE4_70_0_, organisati4_.ORGANISATION_ID as ORGANISA1_66_1_, organisati4_.ORGANISATION_NAME as ORGANISA2_66_1_, organisati4_.ABN as ABN66_1_, organisati4_.WEBSITE_URL as WEBSITE4_66_1_, organisati4_.ENABLED as ENABLED66_1_, organisati4_.STREET_ADDRESS_1 as STREET6_66_1_, organisati4_.STREET_ADDRESS_2 as STREET7_66_1_, organisati4_.CITY as CITY66_1_, organisati4_.POSTCODE as POSTCODE66_1_, organisati4_.STATE_ID as STATE10_66_1_, organisati4_.ORG_OWNER_USER_ID as ORG11_66_1_, organisati4_.ORGANISATION_SUB_TYPE_ID as ORGANIS12_66_1_, person5_.PERSON_ID as PERSON1_52_2_, person5_.FIRST_NAME as FIRST2_52_2_, person5_.LAST_NAME as LAST3_52_2_, person5_.EMAIL as EMAIL52_2_, person5_.PHONE as PHONE52_2_, person5_.MOBILE as MOBILE52_2_, person5_.FAX as FAX52_2_, person5_.STREET_ADDRESS_1 as STREET8_52_2_, person5_.STREET_ADDRESS_2 as STREET9_52_2_, person5_.CITY as CITY52_2_, person5_.POSTCODE as POSTCODE52_2_, person5_.STATE_ID as STATE12_52_2_, person5_1_.USER_NAME as USER2_53_2_, person5_1_.PASSWORD as PASSWORD53_2_, person5_1_.ENABLED as ENABLED53_2_, case when person5_1_.USER_ID is not null then 1 when person5_.PERSON_ID is not null then 0 end as clazz_2_ from ORGANISATION this_ inner join ORGANISATION_PERSON organisati1_ on this_.ORGANISATION_ID=organisati1_.ORGANISATION_ID left outer join ORGANISATION organisati4_ on organisati1_.ORGANISATION_ID=organisati4_.ORGANISATION_ID left outer join PERSON person5_ on organisati1_.PERSON_ID=person5_.PERSON_ID left outer join USERS person5_1_ on person5_.PERSON_ID=person5_1_.USER_ID where this_.ENABLED=? and organisati1_.PERSON_ID=?
Hibernate: select this_.ORGANISATION_ID as ORGANISA1_66_3_, this_.ORGANISATION_NAME as ORGANISA2_66_3_, this_.ABN as ABN66_3_, this_.WEBSITE_URL as WEBSITE4_66_3_, this_.ENABLED as ENABLED66_3_, this_.STREET_ADDRESS_1 as STREET6_66_3_, this_.STREET_ADDRESS_2 as STREET7_66_3_, this_.CITY as CITY66_3_, this_.POSTCODE as POSTCODE66_3_, this_.STATE_ID as STATE10_66_3_, this_.ORG_OWNER_USER_ID as ORG11_66_3_, this_.ORGANISATION_SUB_TYPE_ID as ORGANIS12_66_3_, organisati1_.ORGANISATION_MEMBER_ID as ORGANISA1_68_0_, organisati1_.PARENT_ORGANISATION_ID as PARENT2_68_0_, organisati1_.CHILD_ORGANISATION_ID as CHILD3_68_0_, organisati1_.DATE_MODIFIED as DATE4_68_0_, organisati4_.ORGANISATION_ID as ORGANISA1_66_1_, organisati4_.ORGANISATION_NAME as ORGANISA2_66_1_, organisati4_.ABN as ABN66_1_, organisati4_.WEBSITE_URL as WEBSITE4_66_1_, organisati4_.ENABLED as ENABLED66_1_, organisati4_.STREET_ADDRESS_1 as STREET6_66_1_, organisati4_.STREET_ADDRESS_2 as STREET7_66_1_, organisati4_.CITY as CITY66_1_, organisati4_.POSTCODE as POSTCODE66_1_, organisati4_.STATE_ID as STATE10_66_1_, organisati4_.ORG_OWNER_USER_ID as ORG11_66_1_, organisati4_.ORGANISATION_SUB_TYPE_ID as ORGANIS12_66_1_, organisati5_.ORGANISATION_ID as ORGANISA1_66_2_, organisati5_.ORGANISATION_NAME as ORGANISA2_66_2_, organisati5_.ABN as ABN66_2_, organisati5_.WEBSITE_URL as WEBSITE4_66_2_, organisati5_.ENABLED as ENABLED66_2_, organisati5_.STREET_ADDRESS_1 as STREET6_66_2_, organisati5_.STREET_ADDRESS_2 as STREET7_66_2_, organisati5_.CITY as CITY66_2_, organisati5_.POSTCODE as POSTCODE66_2_, organisati5_.STATE_ID as STATE10_66_2_, organisati5_.ORG_OWNER_USER_ID as ORG11_66_2_, organisati5_.ORGANISATION_SUB_TYPE_ID as ORGANIS12_66_2_ from ORGANISATION this_ inner join ORGANISATION_MEMBER organisati1_ on this_.ORGANISATION_ID=organisati1_.PARENT_ORGANISATION_ID left outer join ORGANISATION organisati4_ on organisati1_.PARENT_ORGANISATION_ID=organisati4_.ORGANISATION_ID left outer join ORGANISATION organisati5_ on organisati1_.CHILD_ORGANISATION_ID=organisati5_.ORGANISATION_ID where this_.ENABLED=? and organisati1_.CHILD_ORGANISATION_ID in (?, ?)
Hibernate: select this_.ORGANISATION_ID as ORGANISA1_66_3_, this_.ORGANISATION_NAME as ORGANISA2_66_3_, this_.ABN as ABN66_3_, this_.WEBSITE_URL as WEBSITE4_66_3_, this_.ENABLED as ENABLED66_3_, this_.STREET_ADDRESS_1 as STREET6_66_3_, this_.STREET_ADDRESS_2 as STREET7_66_3_, this_.CITY as CITY66_3_, this_.POSTCODE as POSTCODE66_3_, this_.STATE_ID as STATE10_66_3_, this_.ORG_OWNER_USER_ID as ORG11_66_3_, this_.ORGANISATION_SUB_TYPE_ID as ORGANIS12_66_3_, organisati1_.ORGANISATION_MEMBER_ID as ORGANISA1_68_0_, organisati1_.PARENT_ORGANISATION_ID as PARENT2_68_0_, organisati1_.CHILD_ORGANISATION_ID as CHILD3_68_0_, organisati1_.DATE_MODIFIED as DATE4_68_0_, organisati4_.ORGANISATION_ID as ORGANISA1_66_1_, organisati4_.ORGANISATION_NAME as ORGANISA2_66_1_, organisati4_.ABN as ABN66_1_, organisati4_.WEBSITE_URL as WEBSITE4_66_1_, organisati4_.ENABLED as ENABLED66_1_, organisati4_.STREET_ADDRESS_1 as STREET6_66_1_, organisati4_.STREET_ADDRESS_2 as STREET7_66_1_, organisati4_.CITY as CITY66_1_, organisati4_.POSTCODE as POSTCODE66_1_, organisati4_.STATE_ID as STATE10_66_1_, organisati4_.ORG_OWNER_USER_ID as ORG11_66_1_, organisati4_.ORGANISATION_SUB_TYPE_ID as ORGANIS12_66_1_, organisati5_.ORGANISATION_ID as ORGANISA1_66_2_, organisati5_.ORGANISATION_NAME as ORGANISA2_66_2_, organisati5_.ABN as ABN66_2_, organisati5_.WEBSITE_URL as WEBSITE4_66_2_, organisati5_.ENABLED as ENABLED66_2_, organisati5_.STREET_ADDRESS_1 as STREET6_66_2_, organisati5_.STREET_ADDRESS_2 as STREET7_66_2_, organisati5_.CITY as CITY66_2_, organisati5_.POSTCODE as POSTCODE66_2_, organisati5_.STATE_ID as STATE10_66_2_, organisati5_.ORG_OWNER_USER_ID as ORG11_66_2_, organisati5_.ORGANISATION_SUB_TYPE_ID as ORGANIS12_66_2_ from ORGANISATION this_ inner join ORGANISATION_MEMBER organisati1_ on this_.ORGANISATION_ID=organisati1_.PARENT_ORGANISATION_ID left outer join ORGANISATION organisati4_ on organisati1_.PARENT_ORGANISATION_ID=organisati4_.ORGANISATION_ID left outer join ORGANISATION organisati5_ on organisati1_.CHILD_ORGANISATION_ID=organisati5_.ORGANISATION_ID where this_.ENABLED=? and organisati1_.CHILD_ORGANISATION_ID in (?)
Hibernate: select this_.ORGANISATION_ID as ORGANISA1_66_3_, this_.ORGANISATION_NAME as ORGANISA2_66_3_, this_.ABN as ABN66_3_, this_.WEBSITE_URL as WEBSITE4_66_3_, this_.ENABLED as ENABLED66_3_, this_.STREET_ADDRESS_1 as STREET6_66_3_, this_.STREET_ADDRESS_2 as STREET7_66_3_, this_.CITY as CITY66_3_, this_.POSTCODE as POSTCODE66_3_, this_.STATE_ID as STATE10_66_3_, this_.ORG_OWNER_USER_ID as ORG11_66_3_, this_.ORGANISATION_SUB_TYPE_ID as ORGANIS12_66_3_, organisati1_.ORGANISATION_MEMBER_ID as ORGANISA1_68_0_, organisati1_.PARENT_ORGANISATION_ID as PARENT2_68_0_, organisati1_.CHILD_ORGANISATION_ID as CHILD3_68_0_, organisati1_.DATE_MODIFIED as DATE4_68_0_, organisati4_.ORGANISATION_ID as ORGANISA1_66_1_, organisati4_.ORGANISATION_NAME as ORGANISA2_66_1_, organisati4_.ABN as ABN66_1_, organisati4_.WEBSITE_URL as WEBSITE4_66_1_, organisati4_.ENABLED as ENABLED66_1_, organisati4_.STREET_ADDRESS_1 as STREET6_66_1_, organisati4_.STREET_ADDRESS_2 as STREET7_66_1_, organisati4_.CITY as CITY66_1_, organisati4_.POSTCODE as POSTCODE66_1_, organisati4_.STATE_ID as STATE10_66_1_, organisati4_.ORG_OWNER_USER_ID as ORG11_66_1_, organisati4_.ORGANISATION_SUB_TYPE_ID as ORGANIS12_66_1_, organisati5_.ORGANISATION_ID as ORGANISA1_66_2_, organisati5_.ORGANISATION_NAME as ORGANISA2_66_2_, organisati5_.ABN as ABN66_2_, organisati5_.WEBSITE_URL as WEBSITE4_66_2_, organisati5_.ENABLED as ENABLED66_2_, organisati5_.STREET_ADDRESS_1 as STREET6_66_2_, organisati5_.STREET_ADDRESS_2 as STREET7_66_2_, organisati5_.CITY as CITY66_2_, organisati5_.POSTCODE as POSTCODE66_2_, organisati5_.STATE_ID as STATE10_66_2_, organisati5_.ORG_OWNER_USER_ID as ORG11_66_2_, organisati5_.ORGANISATION_SUB_TYPE_ID as ORGANIS12_66_2_ from ORGANISATION this_ inner join ORGANISATION_MEMBER organisati1_ on this_.ORGANISATION_ID=organisati1_.PARENT_ORGANISATION_ID left outer join ORGANISATION organisati4_ on organisati1_.PARENT_ORGANISATION_ID=organisati4_.ORGANISATION_ID left outer join ORGANISATION organisati5_ on organisati1_.CHILD_ORGANISATION_ID=organisati5_.ORGANISATION_ID where this_.ENABLED=? and organisati1_.CHILD_ORGANISATION_ID in (?, ?, ?)
Hibernate: select this_.GROUP_ID as GROUP1_59_3_, this_.GROUP_NAME as GROUP2_59_3_, this_.DESCRIPTION as DESCRIPT3_59_3_, groupuser1_.GROUP_USER_ID as GROUP1_58_0_, groupuser1_.GROUP_ID as GROUP2_58_0_, groupuser1_.USER_ID as USER3_58_0_, groupuser1_.DATE_MODIFIED as DATE4_58_0_, group4_.GROUP_ID as GROUP1_59_1_, group4_.GROUP_NAME as GROUP2_59_1_, group4_.DESCRIPTION as DESCRIPT3_59_1_, user5_.USER_ID as PERSON1_52_2_, user5_1_.FIRST_NAME as FIRST2_52_2_, user5_1_.LAST_NAME as LAST3_52_2_, user5_1_.EMAIL as EMAIL52_2_, user5_1_.PHONE as PHONE52_2_, user5_1_.MOBILE as MOBILE52_2_, user5_1_.FAX as FAX52_2_, user5_1_.STREET_ADDRESS_1 as STREET8_52_2_, user5_1_.STREET_ADDRESS_2 as STREET9_52_2_, user5_1_.CITY as CITY52_2_, user5_1_.POSTCODE as POSTCODE52_2_, user5_1_.STATE_ID as STATE12_52_2_, user5_.USER_NAME as USER2_53_2_, user5_.PASSWORD as PASSWORD53_2_, user5_.ENABLED as ENABLED53_2_ from GROUPS this_ inner join GROUP_USER groupuser1_ on this_.GROUP_ID=groupuser1_.GROUP_ID left outer join GROUPS group4_ on groupuser1_.GROUP_ID=group4_.GROUP_ID left outer join USERS user5_ on groupuser1_.USER_ID=user5_.USER_ID left outer join PERSON user5_1_ on user5_.USER_ID=user5_1_.PERSON_ID where groupuser1_.USER_ID=?
Hibernate: select this_.GROUP_ID as GROUP1_59_3_, this_.GROUP_NAME as GROUP2_59_3_, this_.DESCRIPTION as DESCRIPT3_59_3_, organisati1_.ORGANISATION_GROUP_ID as ORGANISA1_69_0_, organisati1_.ORGANISATION_ID as ORGANISA2_69_0_, organisati1_.GROUP_ID as GROUP3_69_0_, organisati1_.DATE_MODIFIED as DATE4_69_0_, organisati4_.ORGANISATION_ID as ORGANISA1_66_1_, organisati4_.ORGANISATION_NAME as ORGANISA2_66_1_, organisati4_.ABN as ABN66_1_, organisati4_.WEBSITE_URL as WEBSITE4_66_1_, organisati4_.ENABLED as ENABLED66_1_, organisati4_.STREET_ADDRESS_1 as STREET6_66_1_, organisati4_.STREET_ADDRESS_2 as STREET7_66_1_, organisati4_.CITY as CITY66_1_, organisati4_.POSTCODE as POSTCODE66_1_, organisati4_.STATE_ID as STATE10_66_1_, organisati4_.ORG_OWNER_USER_ID as ORG11_66_1_, organisati4_.ORGANISATION_SUB_TYPE_ID as ORGANIS12_66_1_, group5_.GROUP_ID as GROUP1_59_2_, group5_.GROUP_NAME as GROUP2_59_2_, group5_.DESCRIPTION as DESCRIPT3_59_2_ from GROUPS this_ inner join ORGANISATION_GROUP organisati1_ on this_.GROUP_ID=organisati1_.GROUP_ID left outer join ORGANISATION organisati4_ on organisati1_.ORGANISATION_ID=organisati4_.ORGANISATION_ID left outer join GROUPS group5_ on organisati1_.GROUP_ID=group5_.GROUP_ID where organisati1_.ORGANISATION_ID in (?, ?, ?, ?, ?, ?)
Hibernate: select this_.GROUP_ID as GROUP1_59_3_, this_.GROUP_NAME as GROUP2_59_3_, this_.DESCRIPTION as DESCRIPT3_59_3_, groupmembe1_.GROUP_MEMBER_ID as GROUP1_61_0_, groupmembe1_.PARENT_GROUP_ID as PARENT2_61_0_, groupmembe1_.CHILD_GROUP_ID as CHILD3_61_0_, groupmembe1_.DATE_MODIFIED as DATE4_61_0_, group4_.GROUP_ID as GROUP1_59_1_, group4_.GROUP_NAME as GROUP2_59_1_, group4_.DESCRIPTION as DESCRIPT3_59_1_, group5_.GROUP_ID as GROUP1_59_2_, group5_.GROUP_NAME as GROUP2_59_2_, group5_.DESCRIPTION as DESCRIPT3_59_2_ from GROUPS this_ inner join GROUP_MEMBER groupmembe1_ on this_.GROUP_ID=groupmembe1_.PARENT_GROUP_ID left outer join GROUPS group4_ on groupmembe1_.PARENT_GROUP_ID=group4_.GROUP_ID left outer join GROUPS group5_ on groupmembe1_.CHILD_GROUP_ID=group5_.GROUP_ID where groupmembe1_.CHILD_GROUP_ID in (?, ?, ?)
Hibernate: select this_.GROUP_ID as GROUP1_59_3_, this_.GROUP_NAME as GROUP2_59_3_, this_.DESCRIPTION as DESCRIPT3_59_3_, groupmembe1_.GROUP_MEMBER_ID as GROUP1_61_0_, groupmembe1_.PARENT_GROUP_ID as PARENT2_61_0_, groupmembe1_.CHILD_GROUP_ID as CHILD3_61_0_, groupmembe1_.DATE_MODIFIED as DATE4_61_0_, group4_.GROUP_ID as GROUP1_59_1_, group4_.GROUP_NAME as GROUP2_59_1_, group4_.DESCRIPTION as DESCRIPT3_59_1_, group5_.GROUP_ID as GROUP1_59_2_, group5_.GROUP_NAME as GROUP2_59_2_, group5_.DESCRIPTION as DESCRIPT3_59_2_ from GROUPS this_ inner join GROUP_MEMBER groupmembe1_ on this_.GROUP_ID=groupmembe1_.PARENT_GROUP_ID left outer join GROUPS group4_ on groupmembe1_.PARENT_GROUP_ID=group4_.GROUP_ID left outer join GROUPS group5_ on groupmembe1_.CHILD_GROUP_ID=group5_.GROUP_ID where groupmembe1_.CHILD_GROUP_ID in (?, ?)
Hibernate: select this_.ROLE_ID as ROLE1_56_3_, this_.ROLE_NAME as ROLE2_56_3_, this_.DESCRIPTION as DESCRIPT3_56_3_, this_.APPLICATION_ID as APPLICAT4_56_3_, grouprole1_.GROUP_ROLE_ID as GROUP1_57_0_, grouprole1_.GROUP_ID as GROUP2_57_0_, grouprole1_.ROLE_ID as ROLE3_57_0_, grouprole1_.DATE_MODIFIED as DATE4_57_0_, group4_.GROUP_ID as GROUP1_59_1_, group4_.GROUP_NAME as GROUP2_59_1_, group4_.DESCRIPTION as DESCRIPT3_59_1_, role5_.ROLE_ID as ROLE1_56_2_, role5_.ROLE_NAME as ROLE2_56_2_, role5_.DESCRIPTION as DESCRIPT3_56_2_, role5_.APPLICATION_ID as APPLICAT4_56_2_ from ROLES this_ inner join GROUP_ROLE grouprole1_ on this_.ROLE_ID=grouprole1_.ROLE_ID left outer join GROUPS group4_ on grouprole1_.GROUP_ID=group4_.GROUP_ID left outer join ROLES role5_ on grouprole1_.ROLE_ID=role5_.ROLE_ID where grouprole1_.GROUP_ID in (?, ?, ?, ?, ?)
Hibernate: select this_.ROLE_ID as ROLE1_56_3_, this_.ROLE_NAME as ROLE2_56_3_, this_.DESCRIPTION as DESCRIPT3_56_3_, this_.APPLICATION_ID as APPLICAT4_56_3_, userrole1_.USER_ROLE_ID as USER1_55_0_, userrole1_.USER_ID as USER2_55_0_, userrole1_.ROLE_ID as ROLE3_55_0_, userrole1_.DATE_MODIFIED as DATE4_55_0_, user4_.USER_ID as PERSON1_52_1_, user4_1_.FIRST_NAME as FIRST2_52_1_, user4_1_.LAST_NAME as LAST3_52_1_, user4_1_.EMAIL as EMAIL52_1_, user4_1_.PHONE as PHONE52_1_, user4_1_.MOBILE as MOBILE52_1_, user4_1_.FAX as FAX52_1_, user4_1_.STREET_ADDRESS_1 as STREET8_52_1_, user4_1_.STREET_ADDRESS_2 as STREET9_52_1_, user4_1_.CITY as CITY52_1_, user4_1_.POSTCODE as POSTCODE52_1_, user4_1_.STATE_ID as STATE12_52_1_, user4_.USER_NAME as USER2_53_1_, user4_.PASSWORD as PASSWORD53_1_, user4_.ENABLED as ENABLED53_1_, role5_.ROLE_ID as ROLE1_56_2_, role5_.ROLE_NAME as ROLE2_56_2_, role5_.DESCRIPTION as DESCRIPT3_56_2_, role5_.APPLICATION_ID as APPLICAT4_56_2_ from ROLES this_ inner join USER_ROLE userrole1_ on this_.ROLE_ID=userrole1_.ROLE_ID left outer join USERS user4_ on userrole1_.USER_ID=user4_.USER_ID left outer join PERSON user4_1_ on user4_.USER_ID=user4_1_.PERSON_ID left outer join ROLES role5_ on userrole1_.ROLE_ID=role5_.ROLE_ID where userrole1_.USER_ID=?
DEBUG - PersonController.secureFormBackingObject(84) | getting form backing object...
DEBUG - PersonManagerImpl.getPerson(106) | getting person with id '8'
Hibernate: select person0_.PERSON_ID as PERSON1_52_0_, person0_.FIRST_NAME as FIRST2_52_0_, person0_.LAST_NAME as LAST3_52_0_, person0_.EMAIL as EMAIL52_0_, person0_.PHONE as PHONE52_0_, person0_.MOBILE as MOBILE52_0_, person0_.FAX as FAX52_0_, person0_.STREET_ADDRESS_1 as STREET8_52_0_, person0_.STREET_ADDRESS_2 as STREET9_52_0_, person0_.CITY as CITY52_0_, person0_.POSTCODE as POSTCODE52_0_, person0_.STATE_ID as STATE12_52_0_, person0_1_.USER_NAME as USER2_53_0_, person0_1_.PASSWORD as PASSWORD53_0_, person0_1_.ENABLED as ENABLED53_0_, case when person0_1_.USER_ID is not null then 1 when person0_.PERSON_ID is not null then 0 end as clazz_0_ from PERSON person0_ left outer join USERS person0_1_ on person0_.PERSON_ID=person0_1_.USER_ID where person0_.PERSON_ID=?
DEBUG - UserManagerImpl.getUserByUserName(178) | getting user with userName 'Test Username 2'
Hibernate: select this_.USER_ID as PERSON1_52_0_, this_1_.FIRST_NAME as FIRST2_52_0_, this_1_.LAST_NAME as LAST3_52_0_, this_1_.EMAIL as EMAIL52_0_, this_1_.PHONE as PHONE52_0_, this_1_.MOBILE as MOBILE52_0_, this_1_.FAX as FAX52_0_, this_1_.STREET_ADDRESS_1 as STREET8_52_0_, this_1_.STREET_ADDRESS_2 as STREET9_52_0_, this_1_.CITY as CITY52_0_, this_1_.POSTCODE as POSTCODE52_0_, this_1_.STATE_ID as STATE12_52_0_, this_.USER_NAME as USER2_53_0_, this_.PASSWORD as PASSWORD53_0_, this_.ENABLED as ENABLED53_0_ from USERS this_ inner join PERSON this_1_ on this_.USER_ID=this_1_.PERSON_ID where this_.USER_NAME=?
Hibernate: select organisati0_.USER_ID as USER3_2_, organisati0_.ORGANISATION_ADMINISTRATOR_ID as ORGANISA1_2_, organisati0_.ORGANISATION_ADMINISTRATOR_ID as ORGANISA1_67_1_, organisati0_.ORGANISATION_ID as ORGANISA2_67_1_, organisati0_.USER_ID as USER3_67_1_, organisati0_.DATE_MODIFIED as DATE4_67_1_, organisati1_.ORGANISATION_ID as ORGANISA1_66_0_, organisati1_.ORGANISATION_NAME as ORGANISA2_66_0_, organisati1_.ABN as ABN66_0_, organisati1_.WEBSITE_URL as WEBSITE4_66_0_, organisati1_.ENABLED as ENABLED66_0_, organisati1_.STREET_ADDRESS_1 as STREET6_66_0_, organisati1_.STREET_ADDRESS_2 as STREET7_66_0_, organisati1_.CITY as CITY66_0_, organisati1_.POSTCODE as POSTCODE66_0_, organisati1_.STATE_ID as STATE10_66_0_, organisati1_.ORG_OWNER_USER_ID as ORG11_66_0_, organisati1_.ORGANISATION_SUB_TYPE_ID as ORGANIS12_66_0_ from ORGANISATION_ADMINISTRATOR organisati0_ inner join ORGANISATION organisati1_ on organisati0_.ORGANISATION_ID=organisati1_.ORGANISATION_ID where organisati0_.USER_ID=?
DEBUG - PersonValidator.validate(34) | entering validate method...
DEBUG - PersonValidator.validate(48) | validating email format...
DEBUG - PersonValidator.validate(71) | Validation passed...
DEBUG - AddressValidator.validate(55) | entering validate method...
DEBUG - AddressValidator.validate(103) | Validation passed...
DEBUG - SimpleFormController.processFormSubmission(257) | No errors -> processing submit
DEBUG - AbstractBaseFormController.onSubmit(118) | Found action method [protected org.springframework.web.servlet.ModelAndView au.com.groupware.profilemanager.web.controller.PersonController.saveAsUser(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse,java.lang.Object,org.springframework.validation.BindException) throws java.lang.Exception]
DEBUG - PersonController.saveAsUser(172) | entering 'saveAsUser' method...
DEBUG - UserManagerImpl.encodeUserPassword(289) | setting password for new user
DEBUG - UserManagerImpl.logPasswordHistory(770) | logging user password history...
Hibernate: insert into PASSWORD_HISTORY (PASSWORD, USER_ID, DATE_PASSWORD_SET) values (?, ?, ?)
WARN - JDBCExceptionReporter.logExceptions(71) | SQL Error: 547, SQLState: 23000
ERROR - JDBCExceptionReporter.logExceptions(72) | INSERT statement conflicted with COLUMN FOREIGN KEY constraint 'FKFDEFF6D04D9A2450'. The conflict occurred in database 'ProfileManagerTest', table 'USERS', column 'USER_ID'.
DEBUG - StateManagerImpl.getStates(34) | getting states from database...
Hibernate: select top 1000 this_.STATE_ID as STATE1_64_0_, this_.STATE_NAME as STATE2_64_0_, this_.COUNTRY_ID as COUNTRY3_64_0_ from STATE this_
DEBUG - PersonController.setupReferenceData(247) | getting state list to populate select list...


Hi All,

I'm not sure if what i'm trying to do is possible or not. I have a class Person that has a joined-subclass of User. The User class extends Person by adding details for username, password and an enabled property. What i'm trying to do is convert an existing Person to a User. the approach i'm taking is this...

1. Get the Person from the database.
2. Instantiate a new User.
3. Using Bean Utils, copy all properties to the new User object from the Person
4. Give the user a userName, password and enabled property.
5. Evict the Person from the session
6. Save the User.

This is throwing exceptions at the database level as i've shown in the logs above. Am I going about this the write way ? Apart from the fact that it isn't working (yet) , i'm also a little concerned that Hibernate won't know how to deal with the collections in the Person.

thanks,
rob


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 03, 2006 9:43 pm 
Newbie

Joined: Tue May 24, 2005 7:08 pm
Posts: 17
Location: Melbourne
After more testing and examination of the logs I realised that the reason this doesn't work is that when you try to save the user Hibernate does not recognise the need for a new record in the User table to correspond to the existing Person record. Subsequently inserts are issued on the database that have a foreign key to the User record that does not exist and the database obviously has a big problem with this.

I read in another thread someone suggested in this specific case where i'm trying to extend an object to an instance of it's subclass that performing a manual insert through jdbc into the User table to create the required User record may fix the problem. This does appear to work although i'm not entirely comfortable with the idea.

Just to clarify what this means, the steps are as follows:

1. Get Person from database
2. Instantiate new User
3. Copy all Person properties to the User
4. Add User details (Username, Password, enabled) to user
5. Create new row in user table with a primary key (also foreign key to Person table) which is the same as the existing person using jdbc.
6. Evict Person from the Hibernate session so we don't get an error due to two objects having the same Id in the Hibernate session.
7. Save User

Does anyone have any comments on this approach ?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 09, 2006 8:16 pm 
Beginner
Beginner

Joined: Mon Apr 24, 2006 9:47 pm
Posts: 33
Location: Kansas City, MO
Example:
Code:
// Create the Person.
Person person = new Person();
person.setThis("blah");
person.setThat("blahblah");
session.persist(person);

// some operations occur...

// Convert the Person to a User.
PreparedStatement ps = connection.prepareStatement("INSERT INTO USER (USER_ID) VALUES (?)");
ps.setInt(1, person.getId());
ps.execute();

User user = (User)session.get(User.class, person.getId());


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 09, 2006 8:17 pm 
Beginner
Beginner

Joined: Mon Apr 24, 2006 9:47 pm
Posts: 33
Location: Kansas City, MO
Problem is, How do you get the JDBC Connection from the SessionFactory or Session?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 09, 2006 8:41 pm 
Newbie

Joined: Tue May 24, 2005 7:08 pm
Posts: 17
Location: Melbourne
Depends on your app architecture but if using Spring try making your jdbc Dao extend Spring's JdbcDaoSupport and inject the Data Source....


then you can write something like this:

Code:
public class UserDAOJdbc extends JdbcDaoSupport
{
   
   /**
    * Inserts a record in the USERS table directly.  This method is used only to aid in conversion of a Person to a User.
    *
    * @param user
    */
   public void insertUser(User user)
   {
      String sql = "insert into USERS (USER_ID, USER_NAME, PASSWORD, ENABLED) values (?,?,?,?)";
     
      SqlUpdate sqlUpdate = new SqlUpdate(this.getDataSource(), sql);
      sqlUpdate.declareParameter(new SqlParameter("USER_ID", Types.INTEGER));
      sqlUpdate.declareParameter(new SqlParameter("USER_NAME", Types.VARCHAR));
      sqlUpdate.declareParameter(new SqlParameter("PASSWORD", Types.VARCHAR));
      sqlUpdate.declareParameter(new SqlParameter("ENABLED", Types.TINYINT));
     
      Object[] params = {user.getId(), user.getUserName(), user.getPassword(), user.getEnabled()};
     
      sqlUpdate.update(params);
     
   }

}


Top
 Profile  
 
 Post subject: Here's another way
PostPosted: Tue Oct 10, 2006 1:08 pm 
Beginner
Beginner

Joined: Mon Apr 24, 2006 9:47 pm
Posts: 33
Location: Kansas City, MO
connection = SessionFactoryUtils.getDataSource(getSessionFactory()).getConnection();


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