By removing the composite key and making
the dataId field be the key the problem was resolved (both query and criteria
work). I like to understand what was the cause of the problem though. I am new
to hibernate, anyone knows enough about hibernate to comment on it?
From: Rakhshani, Mehdi
(GXS)
Sent: Tuesday, September 26, 2006
1:12 PM
To:
Subject: RE: Query.list() returns
one item (as expected) but that item is null (which is unexpected)
I have a simple query that when I execute in sqlplus returns
one record as expected. When I run the same query using hibernate and java, I
get a list back which has one record, but that record is null.
I wrote the same search using Criteria and hibernate
complains that the column name cannot be resolved. Whether I use the
“name” attribute or the “column” attribute of the
property it makes no difference.
Hibernate 3.1: 1,971,632 hibernate3.jar, Windows XP, Oracle
DB
HBM snippet:
<hibernate-mapping package="com.gxs.iefe.alias">
<class
name="AliasTable"
table="IEFE.ALIAS_TABLE"
>
<meta attribute="sync-DAO">false</meta>
<composite-id name="id" class="AliasTablePK">
<key-property
name="owningSystem"
column="OWNING_SYSTEM"
type="string"
/>
<key-property
…
Code snippet using query:
q = theSession.createQuery(
"from
AliasTable where OWNING_SYSTEM = :sys and OWNING_ACCOUNT is null and
OWNING_USER_ID is null and TABLE_NAME = :tbl" );
q.setString( "sys", theOwner.getSystem() );
q.setString( "tbl", theTable );
// Using
q.uniqueResult() produces the same behavior
List anAliasTableList = q.list();
if ( null == anAliasTableList || 0 == anAliasTableList.size()
)
throw new Exception( “Null list“ );
// Code that verifies list size has been removed. “Null list
element” is thrown.
anAliasTable = (AliasTable)anAliasTableList.get( 0 );
if ( null == anAliasTable )
throw new Exception( “Null list element” );
Code snippet using criteria:
Criteria aCriteria = theSession.createCriteria( AliasTable.class );
// Specifying neither property name nor property column works: could not resolve property: owningSystem of: com.gxs.iefe.alias.AliasTable
//aCriteria.add(
Restrictions.eq( "OWNING_SYSTEM", theOwner.getSystem() ) );
aCriteria.add( Restrictions.eq( "owningSystem", theOwner.getSystem() ) );
aCriteria.add( Restrictions.isNull(
"owningAccount" ) );
aCriteria.add( Restrictions.isNull(
"owningUserId" ) );
aCriteria.add( Restrictions.eq( "tableName", theTable ) );
// Retrieve
the data
List anAliasTableList = aCriteria.list();
Any idea why?