Hello,

I'm trying to create my test cases using JUnit. I use Spring 2.5 and Hibernate and PostgreSQL as data base server. But when I try to persist any entity that have Generated Id, I have this problem:
Code:
Hibernate: insert into test (id, name, description) values (?, ?, ?)
Hibernate: select currval('test_id_seq')
WARN  2008-07-04 15:11:26,343 | JDBCExceptionReporter:logExceptions | SQL Error: 0, SQLState: 55000
ERROR 2008-07-04 15:11:26,343 | JDBCExceptionReporter:logExceptions | ERROR: currval of sequence "test_id_seq" is not yet defined in this session
But when I look in the database, the values are persisted. This my spring configurations:
Code:
    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">  
        <property name="driverClassName" value="org.postgresql.Driver" />  
        <property name="url" value="myUrl" />  
        <property name="username" value="postgres" />  
        <property name="password" value="postgres" />  
    </bean>  
	
	<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
		<property name="configLocations" value="classpath*:hibernate.cfg.xml" />
		<property name="schemaUpdate" value="false" />
		<property name="dataSource" ref="dataSource" />
		<property name="hibernateProperties">
		    <props>
		      <prop key="hibernate.hbm2ddl.auto">update</prop>
		      <prop key="hibernate.show_sql">true</prop>
		    </props>
  		</property>
	</bean>

	<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"/>
		
    <context:component-scan base-package="br.com.ajsolucoes"/>
    <context:annotation-config/>
   
    <tx:annotation-driven proxy-target-class="true"/>

My unit test class is:
Code:
public class InitEntityTest {
private static ApplicationContext	factory;

at Test
public void testInitEntity() {
   Test test = new Test();
   test.setDescription("Test");
   test.setName("Test name");
   factory.getBean("myDao").save(test);
}

at Before public void setUp() throws Exception {
   if (factory == null) {
     factory = new ClassPathXmlApplicationContext("classpath*:testeContext.xml");
   }
}
}
Best regards