-->
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.  [ 3 posts ] 
Author Message
 Post subject: How can I map a many to zero association - Null problem???
PostPosted: Tue Feb 15, 2005 8:43 am 
Beginner
Beginner

Joined: Fri Jan 07, 2005 2:47 pm
Posts: 45
I found a lot of exemple on how to handle the many-to-one, many-to-many association but not the many-to-zero association. The problem is when there is no association data that cause a null error. How should I map my association to avoid the null problem?

This is the mapping section code that causing me the null problem:

<many-to-one name="followup"
class="SAP.BusinessObjects.Followup"
cascade="all"
not-null="true"
column= "TEXT_ID"
insert = "false"
update = "false"/>

What should I write instead???

Please could you help.

Hibernate version:
2.1.6
Mapping documents:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping >

<class name="SAP.BusinessObjects.Request"
table="SAMPLES">

<id name="id" type="java.lang.Integer" column="SAMPLE_NUMBER" unsaved-value="0">
<generator class="sequence">
<param name="sequence">SAMPLE_SEQ</param>
</generator>
</id>

<property name="textid"
type="java.lang.String"
length="30"
column="TEXT_ID"/>

<many-to-one name="practitioner"
class="SAP.BusinessObjects.User"
column= "X_REQ_ID" />

<component name="site" class="SAP.BusinessObjects.Site">
<property name="sitename"
type="java.lang.String"
length="20"
not-null="false"
column="X_REQ_COMPANY"/>
<property name="contactname"
type="java.lang.String"
length="50"
column="X_REQ_CONTACT"/>

</component>


<component name="apatient" class="SAP.BusinessObjects.Patient">
<property name="initials"
type="java.lang.String"
length="50"
column ="X_PAT_ID"/>

<property name="gender"
type="java.lang.String"
length="1"
column ="X_PAT_GENDER"/>

</component>

<many-to-one name="followup"
class="SAP.BusinessObjects.Followup"
cascade="all"
not-null="true"
column= "TEXT_ID"
insert = "false"
update = "false"/>

</class>
<query name = "SAP.BusinessObjects.Request.SarInfo">
<![CDATA[from Request request
where request.textid like :textid

]]>
</query>


</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():
Session session=HibernateUtil.getSession();
followupid= followupid + "%";

try{
HibernateUtil.beginTransaction();
Query query = session.getNamedQuery("SAP.BusinessObjects.Request.FollowupInfo");
query.setString("followupid", followupid);

return query.list();

}catch (HibernateException ex){
session.close();
throw new HibernateException (ex);
}
Full stack trace of any exception that occurs:
testAddRequestToWrapper: SAP.Utility.InfrastructureException: net.sf.hibernate.HibernateException: Session is closed

Name and version of the database you are using:
Oracle 9

The generated SQL (show_sql=true):

Hibernate: select request0_.SAMPLE_NUMBER as SAMPLE_N4_, request0_.TEXT_ID as TEXT_ID, request0_.PRIORITY as PRIORITY, request0_.X_MFG_PO as X_MFG_PO, request0_.X_REQ_ID as X_REQ_ID, request0_.X_REQ_COMPANY as X_REQ_CO8_, request0_.X_REQ_CONTACT as X_REQ_CO9_, request0_.X_REQ_ADDRESS1 as X_REQ_A10_, request0_.X_REQ_ADDRESS2 as X_REQ_A11_, request0_.X_REQ_CITY as X_REQ_CITY, request0_.X_REQ_PROVINCE as X_REQ_P13_, request0_.X_REQ_POSTCODE as X_REQ_P14_, request0_.X_REQ_PHONE as X_REQ_P15_, request0_.X_REQ_FAX as X_REQ_FAX, request0_.X_DRUG_BRAND_NAME as X_DRUG_17_, request0_.X_MFG_NAME as X_MFG_NAME, request0_.X_DRUG_ROUTE as X_DRUG_19_, request0_.X_DRUG_FORM as X_DRUG_20_, request0_.X_PAT_ID as X_PAT_ID, request0_.X_PAT_GENDER as X_PAT_GE3_ from SAMPLES request0_ where (request0_.TEXT_ID like ? )
Hibernate: select user0_.REQ_ID as REQ_ID1_, user0_.LAST_NAME as LAST_NAME1_, user0_.DESCRIPTION as DESCRIPT3_1_, user0_.FIRST_NAME as FIRST_NAME1_, user0_.MIDDLE_NAME as MIDDLE_N5_1_, user0_.TITLE as TITLE1_, user0_.CHANGED_ON as CHANGED_ON1_, user0_.ACTIVE as ACTIVE1_, user0_.PSWD as PSWD1_, user0_.SALT as SALT1_, user0_.USERNAME as USERNAME1_, user0_.EXPIRED as EXPIRED1_, user0_.PHONE as PHONE1_, user0_.FAX as FAX1_, user0_.EMAIL as EMAIL1_, user0_.PRIM_LOC as PRIM_LOC1_, site1_.SITE_ID as SITE_ID0_, site1_.CONTACT_NAME as CONTACT_2_0_, site1_.SITE_NAME as SITE_NAME0_, site1_.ADDRESS1 as ADDRESS10_, site1_.ADDRESS2 as ADDRESS20_, site1_.CITY as CITY0_, site1_.PROVINCE as PROVINCE0_, site1_.POSTCODE as POSTCODE0_, site1_.PHONE as PHONE0_, site1_.FAX as FAX0_, site1_.EMAIL as EMAIL0_ from X_REQUESTORS user0_ left outer join X_SITES site1_ on user0_.PRIM_LOC=site1_.SITE_ID where user0_.REQ_ID=?
Hibernate: select followup0_.FOLLOWUP_ID as FOLLOWUP1_0_, followup0_.FOLLOWUP_STATUS as FOLLOWUP2_0_, followup0_.FOLLOWUP_OBSERVATIONS as FOLLOWUP3_0_ from X_FOLLOWUPS followup0_ where followup0_.FOLLOWUP_ID=?

Debug level Hibernate log excerpt:


Top
 Profile  
 
 Post subject: How can I map a many to zero association - Null problem???
PostPosted: Tue Feb 15, 2005 4:00 pm 
Beginner
Beginner

Joined: Fri Jan 07, 2005 2:47 pm
Posts: 45
I don't know if that may help. I just find out that if I write my HQL in my xml file the way show below, it work


<query name = "SAP.BusinessObjects.Request.SarInfo">
<![CDATA[select request.textid
from Request request
left join request.followup up
where request.textid like :textid
and up.status is null

]]>
</query>

But I need to display all fields that normally the SQL will begin like this:

Select *
from......

So is there a way to fix the problem???? since that way I control the null problem?

Thanks


Top
 Profile  
 
 Post subject: How can I map a many to zero association - Null problem???
PostPosted: Wed Feb 16, 2005 8:45 am 
Beginner
Beginner

Joined: Fri Jan 07, 2005 2:47 pm
Posts: 45
Fixed the problem.

If I'm right a set, list, bag or other are used for association one-to-many, many-to-many so do the same for a many-to-zero association and it's worked as it should be. The null problem can be controlled through a query.

If I'm wrong your output is welcome.


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