[hibernate-issues] RE: Query.list() returns one item (as expected) but that item is null (which is unexpected)

Mehdi.Rakhshani at gxs.com Mehdi.Rakhshani at gxs.com
Tue Sep 26 13:11:38 EDT 2006


 

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?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/hibernate-issues/attachments/20060926/9eb6b336/attachment.html 


More information about the hibernate-issues mailing list