-->
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: [SOLVED] nothing returned by find or loadAll
PostPosted: Fri Dec 11, 2009 7:03 am 
Newbie

Joined: Tue Sep 25, 2007 6:30 am
Posts: 10
Hello !

I'm beginning with Hibernate, using Spring and H2.
My problem is i created a table Person (initialized by an initializing bean from spring).
I create a person via hibernate (create an entity by new Person() and set props, then i call getHibernateTemplate.save(person)).
This works because a direct jdbcTemplate SQL query gets me back my record as expected.
But when i use getHibernateTemplate().find("from Person") or getHibernateTemplate.loadAll(Person.class),
i get a List containing one element, but the value of this element is null.
I can't understand why, or what i'm doing wrong.

Here is the log results :
(I must explain that first i made a normal SQL query select * from Person in the jdbcTemplate, but copied the SQL showed by hibernate to be sure we execute the exact same SQL, and because once i had a bad grammar (coming from hibernate !) but it disappeared, dunno why.)

Code:
Hibernate: insert into Person (id, email, firstName, name) values (null, ?, ?, ?)
SQL : select person0_.id as id0_, person0_.email as email0_, person0_.firstName as firstName0_, person0_.name as name0_ from Person person0_
[0] Dummy Frederic dummy@company.com
Hibernate: select person0_.id as id0_, person0_.email as email0_, person0_.firstName as firstName0_, person0_.name as name0_ from Person person0_



Here is my spring config :
Code:
<context:component-scan base-package="org.phoenix.sandbox.hssb.dao"></context:component-scan>

   <!-- DAO -->

   <bean id="abstractDAO" abstract="true"
      class="org.phoenix.sandbox.hssb.dao.AbstractDAO">
      <property name="jdbcTemplate" ref="jdbcTemplate" />
      <property name="hibernateTemplate" ref="hibernateTemplate" />
   </bean>

   <bean id="personDAO" class="org.phoenix.sandbox.hssb.dao.impl.PersonDAOImpl"
      parent="abstractDAO" />

   <!-- Templates -->

   <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
      <property name="dataSource" ref="dataSource" />
   </bean>

   <bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
      <property name="sessionFactory" ref="sessionFactory" />
   </bean>
   
    <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
      <property name="sessionFactory" ref="sessionFactory"/>
   </bean>
   
   <bean id="transactionTemplate" class="org.springframework.transaction.support.TransactionTemplate">
        <property name="transactionManager" ref="transactionManager" />
    </bean>
   
    <tx:annotation-driven />

   <!-- Datasource beans -->

   <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
      destroy-method="close">
      <property name="driverClassName" value="org.h2.Driver" />
      <property name="url" value="jdbc:h2:file:data/hssbdb" />
      <property name="username" value="sa" />
      <property name="password" value="" />
      <!-- number of max active connections -->
      <property name="maxActive" value="10" />
      <property name="maxWait" value="1000" />
      <property name="defaultAutoCommit" value="true" />
   </bean>

   <bean id="sessionFactory"
      class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
      <property name="dataSource" ref="dataSource" />
      <property name="hibernateProperties">
         <props>
            <prop key="hibernate.dialect">org.hibernate.dialect.H2Dialect</prop>
            <prop key="hbm2ddl.auto">create</prop>
            <prop key="hibernate.show_sql">true</prop>
            <prop key="hibernate.autocommit">true</prop>
         </props>
      </property>
      <property name="annotatedClasses">
         <list>
            <value>org.phoenix.sandbox.hssb.model.Person</value>
         </list>
      </property>
   </bean>


Any help would be appreciated a lot !
Frederic


Last edited by vk_phoenixfr on Fri Dec 11, 2009 11:13 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: nothing returned by find or loadAll
PostPosted: Fri Dec 11, 2009 11:06 am 
Newbie

Joined: Tue Sep 25, 2007 6:30 am
Posts: 10
Ok i added a second user, and my hibernate query returns 2 element, all null.
Seems that it gives me back the id only, which would be null.

I annotated the id field with @Generator, with the auto strategy. May be i need to add a generator. I'm looking into this.


Top
 Profile  
 
 Post subject: Re: nothing returned by find or loadAll
PostPosted: Fri Dec 11, 2009 11:12 am 
Newbie

Joined: Tue Sep 25, 2007 6:30 am
Posts: 10
Ok i confirm it was an id problem.
I change my Id generation annotations to this :
@Id
@GeneratedValue(generator="system-uuid")
@GenericGenerator(name="system-uuid", strategy = "uuid")

And now i get my objects with a simple loadAll(Person.class).

Solved !


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.