-->
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: Join table : empty fields --> property = null
PostPosted: Sat May 21, 2005 6:17 am 
Beginner
Beginner

Joined: Wed Mar 30, 2005 5:41 am
Posts: 40
Hibernate version:
3.0.2

Hi,

I have an object Worker with a property avs corresponding to a join table "t_avs".

The type of the avs property is an AVS object.

The property should never be null, so I do the following in my Worker class :
Code:
private AVS avs = new AVS();


When I save my Worker object, a line is created in the "t_avs" table with no data in the fields as expected.

The problem is, when I retrieve a Worker object, Hibernate initializes to null the avs property when all the avs fields are null.

I think this is because if all the fields of a persistent object are null, the object itself is considered as null.

The solution I am thinking about is to add a property to my AVS object with a not null value so the avs property of my Worker object will never be considered as null.

Am I right ? Is there a better solution ?

Best regards
Lilian

Mapping documents:
Worker.hbm.xml:
Code:
<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE hibernate-mapping PUBLIC
   "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
   "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >

<hibernate-mapping>
   <subclass
      name="bab.admin.model.persistent.Worker"
      discriminator-value="worker"
      extends="bab.admin.model.persistent.IParty" >
      
      <!--<property
         name="workedHours"
         formula="( SELECT (HOUR(p.endDate)-HOUR(p.startDate)) FROM t_period p where p.periodId = periodId )" />-->
      
      <!--<property name="workedJobs"
         formula="( SELECT COUNT(mission.serviceWorkerId) FROM t_serviceworker mission
                WHERE mission.partyId = partyId )" />-->
               
        <set
         name="specialities"
         table="t_workerspeciality"
         lazy="true"
         cascade="save-update"
         sort="unsorted" >

         <key column="partyId"></key>

         <many-to-many
            class="bab.admin.model.persistent.Speciality"
            column="specialityId"
            outer-join="auto" />

      </set>
      
      <set
         name="jobsWorker"
         inverse="true" >
      
         <key column="partyId" />
         
         <one-to-many
            class="bab.admin.model.persistent.JobWorker" />
      
      </set>
      
      <join table="t_avs">
      
         <key column="partyId" />
         
         <component name="avs">

            <property name="cotise" column="cotiseYN" type="java.lang.Boolean"/>
            <property name="number" column="avsNumber" />
            <property name="requestDate" />
            <property name="expeditionDate" />
            <property name="receptionDate" />
            
         </component>
      </join>
      
      <join table="t_person">
      
         <key column="partyId" />
         
         <property name="sex" />
         <property name="title" />
         <property name="maritalStatus" column="maritalStatusCode" />
         <property name="birthdate" />
         <property name="accountInfo" />
         
         <component
            name="fullname"
            class="bab.admin.model.persistent.Fullname" >
            <property name="firstname" />
            <property name="lastname" />
         </component>
      </join>
      
      <join table="t_worker">
      
         <key column="partyId" />

         <property name="enabled" type="java.lang.Boolean" update="true"
            insert="true" access="property" column="enabledYN" not-null="false"
            unique="false" />
   
         <property name="critic" type="java.lang.String" update="true"
            insert="true" access="property" column="critic" not-null="false"
            unique="false" />
   
         <property name="compliment" type="java.lang.String"
            update="true" insert="true" access="property" column="compliment"
            not-null="false" unique="false" />
   
         <property name="motivationCode" type="java.lang.String"
            update="true" insert="true" access="property" column="motivationCode"
            not-null="true" unique="false" />
   
         <property name="motivationShortCode" type="java.lang.String"
            update="true" insert="true" access="property"
            column="motivationShortCode" not-null="true" unique="false" />
   
         <property name="affiliationDate" type="java.util.Date"
            update="true" insert="true" access="property"
            column="affiliationDate" not-null="true" unique="false" />
   
         <property name="lastReactivationDate" type="java.util.Date"
            update="true" insert="true" access="property"
            column="lastReactivationDate" not-null="false" unique="false" />
   
         <property name="workPermitCode" type="java.lang.String"
            update="true" insert="true" access="property" column="workPermitCode"
            not-null="true" unique="false" />
   
         <property name="authorizationExpirationDate"
            type="java.util.Date" update="true" insert="true" access="property"
            column="authorizationExpirationDate" not-null="false" unique="false" />
   
         <property name="source" type="java.lang.Boolean" update="true"
            insert="true" access="property" column="sourceYN" not-null="false"
            unique="false" />
            
         <many-to-one
            name="activity"
            column="activityId"  />
      </join>
      
      <join table="t_workerDisponibility" >
         <key column="partyId" />
         
         <component
            name="disponibilities"
            class="bab.admin.model.persistent.Disponibility" >
         
            <property name="mondayMorning" column="mondayMorningYN" />
            <property name="mondayAfternoon" column="mondayAfternoonYN" />
            <property name="mondayNight" column="mondayNightYN" />
            <property name="tuesdayMorning" column="tuesdayMorningYN" />
            <property name="tuesdayAfternoon" column="tuesdayAfternoonYN" />
            <property name="tuesdayNight" column="tuesdayNightYN" />
            <property name="wednesdayMorning" column="wednesdayMorningYN" />
            <property name="wednesdayAfternoon" column="wednesdayAfternoonYN" />
            <property name="wednesdayNight" column="wednesdayNightYN" />
            <property name="thursdayMorning" column="thursdayMorningYN" />
            <property name="thursdayAfternoon" column="thursdayAfternoonYN" />
            <property name="thursdayNight" column="thursdayNightYN" />
            <property name="fridayMorning" column="fridayMorningYN" />
            <property name="fridayAfternoon" column="fridayAfternoonYN" />
            <property name="fridayNight" column="fridayNightYN" />
            <property name="saturdayMorning" column="saturdayMorningYN" />
            <property name="saturdayAfternoon" column="saturdayAfternoonYN" />
            <property name="saturdayNight" column="saturdayNightYN" />
            <property name="sundayMorning" column="sundayMorningYN" />
            <property name="sundayAfternoon" column="sundayAfternoonYN" />
            <property name="sundayNight" column="sundayNightYN" />
            
            <property name="february" column="februaryYN" />
            <property name="paques" column="paquesYN" />
            <property name="summer" column="summerYN" />
            <property name="autumn" column="autumnYN" />
            <property name="noel" column="noelYN" />
            <property name="jeunegenevois" column="jeunegenevoisYN" />
            <property name="ascension" column="ascensionYN" />
            <property name="pentecote" column="pentecoteYN" />
         </component>
      </join>
   </subclass>

</hibernate-mapping>


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.