-->
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: Hibernate gives all NULL-objects not hydrated-trace logs att
PostPosted: Thu Dec 17, 2009 12:04 pm 
Newbie

Joined: Thu Dec 17, 2009 11:43 am
Posts: 6
Hi All,

I used Hibernate Tools to generate code for a table which had no primary key. Hibernate created two classes- one with all columns in table which is used as composite primary key.

Here is configuration file,
Code:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory>
        <property name="hibernate.bytecode.use_reflection_optimizer">false</property>
        <property name="hibernate.connection.driver_class">oracle.jdbc.OracleDriver</property>
        <property name="hibernate.connection.password">******</property>
        <property name="hibernate.connection.url">jdbc:oracle:thin:@******:1521:******</property>
        <property name="hibernate.connection.username">******</property>
        <property name="hibernate.dialect">org.hibernate.dialect.Oracle9iDialect</property>
        <property name="show_sql">true</property>
        <property name="current_session_context_class">thread</property>
        <mapping resource="somepackage/Parent.hbm.xml" />
    </session-factory>
</hibernate-configuration>


Here is mapping file,

Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Dec 17, 2009 8:26:38 PM by Hibernate Tools 3.2.4.GA -->
<hibernate-mapping>
    <class name="somepackage.Parent" table="PARENT" schema="SOMESCHEMA">
        <composite-id name="id" class="somepackage.ParentId">
            <key-property name="prop1" type="string">
                <column name="PROP1" length="16" />
            </key-property>
            <key-property name="prop2" type="string">
                <column name="PROP2" length="10" />
            </key-property>
            <key-property name="prop3" type="big_decimal">
                <column name="PROP3" precision="38" scale="0" />
            </key-property>
        </composite-id>
    </class>
</hibernate-mapping>



The problem that I am facing is whenever I run following code I get list with all null values. Could anyone please explain me what is going wrong?

Code:
public class Test {

   /**
    * @param args
    */
   public static void main(String[] args) {
      // TODO Auto-generated method stub
      Configuration cfg = new Configuration().configure("hibernate.cfg.xml");
      SessionFactory fact = cfg.buildSessionFactory();
      Session session = fact.openSession();
      Transaction tx = session.beginTransaction();
      String hql = "from Parent fetch all properties where id.prop1 = 'tt1'";
      Query query = session.createQuery(hql);
      List<Parent> results = query.list();
      for(Parent rf: results) {
         ParentId id = rf.getId();
         System.out.println(getProp1());
      }
      tx.commit();
      fact.close();
   }

}


Last edited by ajay.rivendell on Wed Dec 23, 2009 10:18 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: query returning list with all null- trace logs attached*
PostPosted: Wed Dec 23, 2009 9:13 am 
Newbie

Joined: Thu Dec 17, 2009 11:43 am
Posts: 6
Hi,

Below are the trace logs. Could anyone from Hibernate team please point out what is wrong, perhaps I am missing some basic configuration, or mapping is wrong, the part that I feel wrong is - total objects hydrated: 0 and result row = null.


Note that data is correctly fetched from database. It is just that the list that I get contains all NULL values.

Please let me know if additional details are required.

Code:
18:21:53,272 DEBUG Loader:699 - result set row: 230
18:21:53,272 TRACE LongType:172 - returning '261' as column: COUNTRY1_2_
18:21:53,272 TRACE StringType:172 - returning 'Yugoslavia' as column: COUNTRY2_2_
18:21:53,272 TRACE CharacterType:172 - returning 'Y' as column: ACTIVE3_2_
18:21:53,272 TRACE StringType:172 - returning 'Yugoslavia' as column: SHORT4_2_
18:21:53,272 TRACE StringType:172 - returning 'yu' as column: ISO5_2_
18:21:53,272 TRACE LongType:172 - returning '5' as column: REGION6_2_
18:21:53,272 TRACE LongType:172 - returning '11' as column: SUB7_2_
18:21:53,272 TRACE TimestampType:172 - returning '1999-05-28 20:07:23' as column: CREATION8_2_
18:21:53,272 TRACE LongType:172 - returning '1004' as column: CREATED9_2_
18:21:53,272 TRACE TimestampType:172 - returning '2003-05-07 11:09:03' as column: LAST10_2_
18:21:53,272 TRACE LongType:172 - returning '2328' as column: LAST11_2_
18:21:53,272 TRACE LongType:166 - returning null as column: PROGRAM12_2_
18:21:53,272 DEBUG Loader:1173 - result row: null
18:21:53,288 DEBUG Loader:699 - result set row: 231
18:21:53,288 TRACE LongType:172 - returning '266' as column: COUNTRY1_2_
18:21:53,288 TRACE StringType:172 - returning 'Jersey' as column: COUNTRY2_2_
18:21:53,288 TRACE CharacterType:172 - returning 'Y' as column: ACTIVE3_2_
18:21:53,288 TRACE StringType:166 - returning null as column: SHORT4_2_
18:21:53,288 DEBUG Loader:1173 - result row: null
18:21:53,288 TRACE Loader:721 - done processing result set (232 rows)
18:21:53,288 DEBUG AbstractBatcher:389 - about to close ResultSet (open ResultSets: 1, globally: 1)
18:21:53,288 DEBUG AbstractBatcher:374 - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
18:21:53,288 TRACE AbstractBatcher:533 - closing statement
18:21:53,522 TRACE Loader:851 - total objects hydrated: 0
18:21:53,522 DEBUG StatefulPersistenceContext:837 - initializing non-lazy collections
java.lang.NullPointerException
   at Test.main(Unknown Source)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
   at java.lang.reflect.Method.invoke(Unknown Source)
   at org.apache.tools.ant.taskdefs.ExecuteJava.run(ExecuteJava.java:217)
   at org.apache.tools.ant.taskdefs.ExecuteJava.execute(ExecuteJava.java:152)
   at org.apache.tools.ant.taskdefs.Java.run(Java.java:764)
   at org.apache.tools.ant.taskdefs.Java.executeJava(Java.java:218)
   at org.apache.tools.ant.taskdefs.Java.executeJava(Java.java:132)
   at org.apache.tools.ant.taskdefs.Java.execute(Java.java:105)
   at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
   at java.lang.reflect.Method.invoke(Unknown Source)
   at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
   at org.apache.tools.ant.Task.perform(Task.java:348)
   at org.apache.tools.ant.Target.execute(Target.java:357)
   at org.apache.tools.ant.Target.performTasks(Target.java:385)
   at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1337)
   at org.apache.tools.ant.Project.executeTarget(Project.java:1306)
   at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
   at org.eclipse.ant.internal.ui.antsupport.EclipseDefaultExecutor.executeTargets(EclipseDefaultExecutor.java:32)
   at org.apache.tools.ant.Project.executeTargets(Project.java:1189)
   at org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.run(InternalAntRunner.java:423)
   at org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.main(InternalAntRunner.java:137)
18:21:53,538 DEBUG JDBCTransaction:152 - rollback
18:21:53,772 DEBUG JDBCTransaction:163 - rolled back JDBC Connection
18:21:53,772 TRACE JDBCContext:219 - after transaction completion
18:21:53,772 DEBUG ConnectionManager:404 - aggressively releasing JDBC connection
18:21:53,772 DEBUG ConnectionManager:441 - releasing JDBC connection [ (open PreparedStatements: 0, globally: 0) (open ResultSets: 0, globally: 0)]
18:21:53,772 TRACE DriverManagerConnectionProvider:129 - returning connection to pool, pool size: 1
18:21:53,772 TRACE SessionImpl:422 - after transaction completion
18:21:53,772 TRACE SessionImpl:273 - closing session
18:21:53,772 TRACE ConnectionManager:375 - connection already null in cleanup : no action
18:21:53,772  INFO SessionFactoryImpl:769 - closing
18:21:53,772  INFO DriverManagerConnectionProvider:147 - cleaning up connection pool


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.