-->
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.  [ 1 post ] 
Author Message
 Post subject: Strange issue with Hibernate
PostPosted: Sun Nov 13, 2005 12:40 pm 
Newbie

Joined: Sun Nov 13, 2005 12:31 pm
Posts: 3
Well, I have a simple system, where I register a project and create a elements tree of that project(using framework spring). I'm facing the follow issue: When I register a project and list the registered projects the last project registered don't appears in the list. So, I update the page and the project appears. If I update again, the project don't appears, and this behavior seems to be random. The data vary between two states, before the DB update, and after it. If I restart the TomCat this behavior stops.



The data recover and persistence uses Postgres DB and Hibernate component.


Hibernate version: 3.0.5

Mapping documents:

<!--##############################
HIBERNATE CONFIG
##############################-->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource"><ref local="dataSource"/></property>
<property name="hibernateProperties"><ref local="hibernateProperties"/></property>
<property name="mappingResources"><ref bean="mappingResources" /></property>
</bean>

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName"><value>org.postgresql.Driver</value></property>
<property name="url"><value>jdbc:postgresql://localhost:5432/SIMAGE</value></property>
<property name="username"><value>postgres</value></property>
<property name="password"><value>sspw2005</value></property>
</bean>

<bean id="hibernateProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="properties">
<props>
<prop key="hibernate.connection.username">xxxx</prop>
<prop key="hibernate.connection.password">xxxx</prop>
<prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</prop>
<prop key="hibernate.show_sql">false</prop>
</props>
</property>
</bean>

<bean id="mappingResources" class="java.util.ArrayList">
<constructor-arg>
<list>
<value>/hibernate/User.hbm.xml</value>
<value>/hibernate/Project.hbm.xml</value>
<value>/hibernate/TreeNode.hbm.xml</value>
</list>
</constructor-arg>
</bean>

<bean id="HibernateUtil" class="br.com.simageWeb.util.HibernateUtil">
<property name="sessionFactory"><ref bean="sessionFactory"/></property>
</bean>

<!--##############################
PROJECT MAPPING
##############################-->
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
<class name="br.com.simageWeb.models.Project" table='"SIM_PROJECT"'>

<id name="pkProject" type="long" unsaved-value="null" >
<column name="pkproject" sql-type="integer" not-null="true"/>
<generator class="increment">
<param name="sequence">seq_project</param>
</generator>
</id>

<property name="name">
<column name="name" length="50"/>
</property>

<property name="mission">
<column name="mission" length="50"/>
</property>

<property name="problem">
<column name="problem" length="50"/>
</property>

<property name="level">
<column name="level"/>
</property>

<property name="excluded">
<column name="excluded"/>
</property>

<property name="type">
<column name="type"/>
</property>

<property name="launchingType">
<column name="launchingtype"/>
</property>

<property name="simulationsCount">
<column name="simulationscount"/>
</property>

<set name="users" table='"SIM_USERPROJECT"'>
<key column="fkproject"/>
<many-to-many column="fkuser" class="br.com.simageWeb.models.User"/>
</set>

<set name="SCFs" cascade="all" table='"SIM_PROJECTSCF"'>
<key column="fkproject"/>
<many-to-many column="fktreenode" class="br.com.simageWeb.models.TreeNode"/>
</set>

</class>
</hibernate-mapping>

Code between sessionFactory.openSession() and session.close():
public class HibernateUtil {

private static Log log = LogFactory.getLog(HibernateUtil.class);
private static SessionFactory sessionFactory;
public static final ThreadLocal session = new ThreadLocal();

public static Session currentSession() {
Session s = (Session) session.get();
// Open a new Session, if this Thread has none yet
if (s == null) {
s = sessionFactory.openSession();
session.set(s);
}
return s;
}

public static void closeSession() {
Session s = (Session) session.get();
if (s != null)
s.close();
session.set(null);
}

public SessionFactory getSessionFactory() {
return HibernateUtil.sessionFactory;
}

public void setSessionFactory(SessionFactory sessionFactory) {
HibernateUtil.sessionFactory = sessionFactory;
}
}

public class ProjectDaoPostgres {

....
public boolean store(Object o) {
Session session = HibernateUtil.currentSession();
Transaction tx = session.beginTransaction();
session.persist(o);
tx.commit();
return true;
}

...

public Iterator retrieveAll() {
Session session = HibernateUtil.currentSession();
Transaction tx = session.beginTransaction();
Query query = session.createQuery("from Project where excluded != 1 order by name");
tx.commit();
return query.iterate();
}
...

}

Full stack trace of any exception that occurs:

Name and version of the database you are using:
PostgreSQL 8.0.1

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.