-->
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: Using is null in one-to-one with property-ref to properties
PostPosted: Wed Aug 04, 2010 12:30 pm 
Newbie

Joined: Thu Oct 06, 2005 12:30 pm
Posts: 10
Using: hibernate-core-3.3.2.GA.jar

I'd like to map a legacy relation using a group of properties, where one of the property values is null.

I have a class mapping like this, where the director relation is optional:

Code:
 
  <class name="Process" table="process" lazy="true">
    <id name="id" type="java.lang.Long" column="processId" unsaved-value="null">
      <generator class="native"/>
    </id>
    <version name="lastModified" type="timestamp"/>
    <properties name="ownerStatusDirector">
      <many-to-one name="owner" class="Person" column="ownerId" insert="true" update="false"/>
      <property name="statusCode" type="java.lang.String"/>
      <many-to-one name="director" class="Person" column="directorId" insert="true" update="false"/>
    </properties>
    . . .
  </class>


I'd then like to have a person mapping with a one-to-one relation to their active process, where director is null.

Code:
  <class name="Person" table="person" lazy="true">
    <id name="id" type="java.lang.Long" column="personId" unsaved-value="null">
      <generator class="native" />
    </id>
    <version name="lastModified" type="timestamp"/>
    . . .
    <one-to-one name="activeDirectorlessProcess" outer-join="false" foreign-key="ownerId"
      property-ref="ownerStatusDirector" lazy="proxy" cascade="all">
      <formula>ownerId</formula>
      <formula>'A'</formula>
      <formula>null</formula>
    </one-to-one>
    . . .
  </class>


This generates the following SQL:
Code:
. . .
where process0_.ownerId=7103 and process0_.status='A' and process0_.directorId=null


Obviously, "=null" will not work, and instead I need "is null". Can someone point me in the right direction to map this?


Top
 Profile  
 
 Post subject: Re: Using is null in one-to-one with property-ref to properties
PostPosted: Wed Aug 04, 2010 3:00 pm 
Newbie

Joined: Thu Oct 06, 2005 12:30 pm
Posts: 10
I think I have a workaround for this. I mapped the Process class twice using an entity-name to distinguish the second one which has a where clause:

Code:
 
  <class name="Process" table="process" lazy="true">
    . . .
  </class>

  <class name="Process" entity-name="ProcessWithoutDirector" table="process" lazy="true"
    where="directorId is null">
    . . .
    <properties name="ownerStatus">
      <many-to-one name="owner" class="Person" column="ownerId" insert="true" update="false"/>
      <property name="statusCode" type="java.lang.String"/>
    </properties>
    . . .
  </class>


So then the person mapping relates to the ProcessWithoutDirector:

Code:
  <class name="Person" table="person" lazy="true">
    . . .
    <one-to-one name="activeDirectorlessProcess" entity-name="ProcessWithoutDirector"
      outer-join="false" foreign-key="ownerId"
      property-ref="ownerStatus" lazy="proxy" cascade="all">
      <formula>ownerId</formula>
      <formula>'A'</formula>
    </one-to-one>
    . . .
  </class>


I'm not sure if this is the best solution, but it does seem to work.


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.