-->
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.  [ 6 posts ] 
Author Message
 Post subject: Changes not committing (Hib3, Spring 1.2, Oracle 9
PostPosted: Mon Jul 24, 2006 4:42 pm 
Newbie

Joined: Mon Jul 24, 2006 4:16 pm
Posts: 7
Location: Lapland
Hi,

I have a simple mapping. I create and populate the POJOs, call saveOrUpdate(), and then flush(), but the changes are not being committed (see subject line for environment)

No error messages appear, but the row is not inserted in the table, even after the app server is shut down (which is JBoss 4).

POJO class:

public class Environment
{
private Long environmentId;
private String name;
private Set applications = new HashSet();
private Date createdOn;
private String createdBy;
private Date updatedOn;
private String updatedBy;

... getters and setters omitted ...
}

Mapping:

<class name="com.mydomain.Environment" table="ENVIRONMENT">

<id name="environmentId" column="environment_id" type="long">
<generator class="sequence">
<param name="sequence">environment_id_sq</param>
</generator>
</id>

<property name="name" column="name" />
<property name="createdOn" column="created_on" />
<property name="createdBy" column="created_by" />
<property name="updatedOn" column="updated_on" />
<property name="updatedBy" column="updated_by" />

<set name="applications" table="APPLICATION" lazy="true">
<key column="ENVIRONMENT_ID" />
<one-to-many class="com.geai.b2b.domain.Application" />
</set>

</class>

DAO code:

public class EnvironmentDao extends HibernateDaoSupport
{
public void saveOrUpdate(Environment e)
{
getHibernateTemplate().saveOrUpdate( e );
getHibernateTemplate().flush();
}
}

Test code:

Environment env = new Environment();
env.setCreatedBy("andrew");
env.setCreatedOn(new Date());
env.setUpdatedBy("andrew");
env.setUpdatedOn(new Date());
env.setName("Production");

environmentDao.saveOrUpdate(env);

Generated SQL:

15:38:50,734 INFO [STDOUT] Hibernate: select environment_id_sq.nextval from dual
15:38:50,859 INFO [STDOUT] Hibernate: insert into ENVIRONMENT (name, created_on, created_by, updated_on, updated_by, environment_id) values (?, ?, ?, ?, ?, ?)

Any help appreciated!

Thanks,

Andrew Broderick

_________________
1-800-flowers.com? How on earth do you reach these people?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 24, 2006 5:22 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
seems like your Spring config is messing up with transactions

_________________
Emmanuel


Top
 Profile  
 
 Post subject: applicationContext.xml and hibernate.cfg.xml
PostPosted: Mon Jul 24, 2006 5:35 pm 
Newbie

Joined: Mon Jul 24, 2006 4:16 pm
Posts: 7
Location: Lapland
Here is the contents of applicationContext.xml:

<beans>

<bean id="sessionFactoryMessageDB" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="mappingDirectoryLocations">
<list>
<value>classpath:/com/mydomain</value>
</list>
</property>
<property name="configLocation">
<value>classpath:hibernate.cfg.xml</value>
</property>
</bean>

<bean id="hibernateTemplateMessageDB" class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory">
<ref bean="sessionFactoryMessageDB" />
</property>
</bean>

<bean id="environmentDao" class="com.mydomain.EnvironmentDao">
<property name="hibernateTemplate">
<ref bean="hibernateTemplateMessageDB" />
</property>
</bean>

<!-- ************ STRUTS ACTIONS ****************** -->

<bean name="/TestAction" class="com.geai.b2b.struts.action.TestAction" >
<property name="environmentDao">
<ref bean="environmentDao" />
</property>
</bean>

</beans>

and here is the single hibernate.cfg.xml:

<hibernate-configuration>

<session-factory>
<property name="show_sql">true</property>
<property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="connection.url">jdbc:oracle:thin:@ ... DB URL omitted ...</property>
<property name="dialect">org.hibernate.dialect.OracleDialect</property>

<!-- Mapping files -->
<property name="connection.username">.....</property>
<property name="connection.password">....</property>

</session-factory>

</hibernate-configuration>

What in those files would change the transaction behavior?

-Andrew

_________________
1-800-flowers.com? How on earth do you reach these people?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 24, 2006 8:29 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
I don't use Spring, so can't help you here

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 24, 2006 8:55 pm 
Newbie

Joined: Wed Jul 19, 2006 2:59 pm
Posts: 5
in your config file, it seems that you haven't declared a transaction manager. plus from your code I haven't seen any transactional code.
you need to add this to the config file:
Code:
<bean id="transactionManager" class="org.springframework.orm.hibernate.HibernateTransactionManager">
<property name="sessionFactory"><ref local="sessionFactory"/></property>
   </bean>


and in your test class make sure you start a transaction and commit.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 24, 2006 8:57 pm 
Newbie

Joined: Wed Jul 19, 2006 2:59 pm
Posts: 5
in your config file, it seems that you haven't declared a transaction manager. plus from your code I haven't seen any transactional code.
you need to add this to the config file:
Code:
<bean id="transactionManager" class="org.springframework.orm.hibernate.HibernateTransactionManager">
<property name="sessionFactory"><ref local="sessionFactory"/></property>
   </bean>


and in your test class make sure you start a transaction and commit.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 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.