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