-->
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: Workaround w/ DB returns composite-id key-property of null?
PostPosted: Mon Aug 29, 2005 5:27 pm 
Newbie

Joined: Mon Aug 29, 2005 5:01 pm
Posts: 5
I'm encountering a problem when retrieving persisted objects from a legacy database where a subset of the columns in the composite ID are null (i.e. last_name, see bellow). The row in the database is not hydrated and hibernate returns a null object. Is there a way to retrieve hydrated objects where these parameters are simply null?

Thanks,

PT



Hibernate version:
3.0.1

Mapping documents:
<class name="Contact"
table="contact"
>
<composite-id>
<key-property
name="lastName"
column="last_name"
type="java.lang.String"
length="20"
>
</key-property>

<key-property
name="firstName"
column="first_name"
type="java.lang.String"
length="20"
/>
<key-property
name="contactName"
column="contact_name"
type="java.lang.String"
length="35"
/>
<key-property
name="contactEmail"
column="contact_email"
type="java.lang.String"
length="30"
/>
</composite-id> ...

Code from DAO to search for contacts:

public List<Contact> getContacts(final ContactSearchInputBean bean){
return (List) getHibernateTemplate().execute(new HibernateCallback() {
public Object doInHibernate(Session session) throws HibernateException {
Criteria criteria = session.createCriteria(Contact.class);
criteria.add( Expression.like(Contact.PROPERTYNAME_CONTACTEMAIL ,
bean.getContact(), MatchMode.ANYWHERE) );
return criteria.list();
}
});
}

Name and version of the database you are using:
INFORMIX-OnLine Version 7.20.UC4

The generated SQL (show_sql=true):
35115 [AWT-EventQueue-0] DEBUG org.hibernate.SQL - select this_.last_name as last1_0_, this_.contact_key as contact2_0_, this_.first_name as first3_0_, this_.contact_email as contact4_0_, this_.contact_date_added as contact5_0_, this_.middle_name as middle6_0_, this_.contact_phone as contact7_0_, this_.contact_name as contact8_0_, this_.contact_fax as contact9_0_0_, this_.contact_home as contact10_0_0_, this_.contact_card as contact11_0_0_, this_.contact_addr as contact12_0_0_, this_.contact_city as contact13_0_0_, this_.contact_state as contact14_0_0_, this_.contact_zip as contact15_0_0_, this_.contact_org as contact16_0_0_, this_.contact_title as contact17_0_0_, this_.contact_dept as contact18_0_0_, this_.contact_cell as contact19_0_0_, this_.contact_pager as contact20_0_0_, this_.contact_notes as contact21_0_0_, this_.contact_xmas as contact22_0_0_, this_.contact_date_mod as contact23_0_0_, this_.contact_owner as contact24_0_0_, this_.contact_share as contact25_0_0_, this_.contact_group as contact26_0_0_ from contact this_ where this_.contact_email like ?

Debug level Hibernate log excerpt:

35199 [AWT-EventQueue-0] DEBUG org.hibernate.loader.Loader - processing result set
35199 [AWT-EventQueue-0] DEBUG org.hibernate.loader.Loader - result set row: 0
35199 [AWT-EventQueue-0] DEBUG org.hibernate.type.StringType - returning null as column: last1_0_
35200 [AWT-EventQueue-0] DEBUG org.hibernate.loader.Loader - result row: null
35200 [AWT-EventQueue-0] DEBUG org.hibernate.loader.Loader - done processing result set (1 rows)


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.