-->
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.  [ 4 posts ] 
Author Message
 Post subject: Persistent object not updated
PostPosted: Thu Jul 19, 2007 9:59 am 
Beginner
Beginner

Joined: Thu May 10, 2007 4:20 am
Posts: 27
Hello,

I'm experiencing the following problem:

I update a property value of a persistent object in my code,
but the appropriate value is not updated in the database.

I went through the documentation & forum but couldn't find anything similar there.
I'll really appreciate any help!
Following the details:

Hibernate version:
3.2.3.ga

Mapping documents:

hibernate.cfg.xml:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>

<session-factory>

<!-- Database connection settings -->
<property name="connection.driver_class">net.sourceforge.jtds.jdbc.Driver</property>
<property name="connection.url">jdbc:jtds:sqlserver://IP/DB;charset=cp1255</property>
<property name="connection.instance">SQLEXPRESS</property>
<property name="connection.username">USER</property>
<property name="connection.password">PWD</property>

<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property>

<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.SQLServerDialect</property>

<!-- Enable Hibernate's automatic session context management -->
<property name="current_session_context_class">thread</property>

<!-- Disable the second-level cache -->
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>

<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>

<mapping resource="path/to/file/Class2.hbm.xml"/>
<mapping resource="path/to/file/Class1.hbm.xml"/>

</session-factory>

</hibernate-configuration>


Class1.cfg.xml:

<?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="path.to.class.Class1" table="table1" lazy="false">
<composite-id>
<key-property name="id1" column="id1"/>
<key-many-to-one name="foreignKey" class="path.to.class.Class2" column="foreign_key" lazy="false"/>
<key-property name="id2" column="id2"/>
</composite-id>
</class>
</hibernate-mapping>


Class2.cfg.xml:

<?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="path.to.class.Class2" table="table2">
<id name="id" column="id">
<generator class="org.hibernate.id.enhanced.TableGenerator">
<param name="segment_value">sequence1</param>
<param name="initial_value">1</param>
</generator>

</id>
<property name="property1" column="property1"/>
<property name="property2" column="property2"/>
<property name="property3" column="property3"/>
<property name="property4" column="property4"/>
<property name="property5" column="property5"/>
</class>
</hibernate-mapping>

HibernateUtil.java:
public class HibernateUtil
{

private static final SessionFactory sessionFactory;

static
{
try
{
// Create the SessionFactory from hibernate.cfg.xml

sessionFactory = new Configuration().configure().buildSessionFactory();

}
catch (Throwable ex) {
// Make sure you log the exception, as it might be swallowed
System.err.println("Initial SessionFactory creation failed." + ex);
throw new ExceptionInInitializerError(ex);
}

}

public static SessionFactory getSessionFactory() {
return sessionFactory;
}
}

Code between sessionFactory.openSession() and session.close():

Transaction tr;

tr = HibernateUtil.getSessionFactory().getCurrentSession().beginTransaction();
List objects = HibernateUtil.getSessionFactory().getCurrentSession().createQuery("from Class1 where id1=11").list();
Class1 object1 = (Class1) objects.get(0);
object1.setid2(new Integer(6)); //the appropriate property is changed here, but this change is not reflected in the DB
HibernateUtil.getSessionFactory().getCurrentSession().flush();
tr.commit();

Full stack trace of any exception that occurs:
-
Name and version of the database you are using:
SQL Server 2005
The generated SQL (show_sql=true):

Hibernate: select grouphiera0_.id1 as object11_2_, grouphiera0_.foreign_key as asset2_2_, grouphiera0_.id2 as object13_2_ from table1 grouphiera0_ where grouphiera0_.id1=11
Hibernate: select assetgroup0_.id as id1_0_, assetgroup0_.property1 as name2_1_0_, assetgroup0_.property2 as descript3_1_0_, assetgroup0_.property3 as conversion4_1_0_, assetgroup0_.property4 as target5_1_0_, assetgroup0_.property5 as accepted6_1_0_ from table2 assetgroup0_ where assetgroup0_.id=?
Hibernate: select assetgroup0_.id as id1_0_, assetgroup0_.property1 as name2_1_0_, assetgroup0_.property2 as descript3_1_0_, assetgroup0_.property3 as conversion4_1_0_, assetgroup0_.property4 as target5_1_0_, assetgroup0_.property5 as accepted6_1_0_ from table2 assetgroup0_ where assetgroup0_.id=?
Hibernate: select assetgroup0_.id as id1_0_, assetgroup0_.property1 as name2_1_0_, assetgroup0_.property2 as descript3_1_0_, assetgroup0_.property3 as conversion4_1_0_, assetgroup0_.property4 as target5_1_0_, assetgroup0_.property5 as accepted6_1_0_ from table2 assetgroup0_ where assetgroup0_.id=?
Hibernate: select assetgroup0_.id as id1_0_, assetgroup0_.property1 as name2_1_0_, assetgroup0_.property2 as descript3_1_0_, assetgroup0_.property3 as conversion4_1_0_, assetgroup0_.property4 as target5_1_0_, assetgroup0_.property5 as accepted6_1_0_ from table2 assetgroup0_ where assetgroup0_.id=?
Hibernate: select assetgroup0_.id as id1_0_, assetgroup0_.property1 as name2_1_0_, assetgroup0_.property2 as descript3_1_0_, assetgroup0_.property3 as conversion4_1_0_, assetgroup0_.property4 as target5_1_0_, assetgroup0_.property5 as accepted6_1_0_ from table2 assetgroup0_ where assetgroup0_.id=?
Hibernate: select assetgroup0_.id as id1_0_, assetgroup0_.property1 as name2_1_0_, assetgroup0_.property2 as descript3_1_0_, assetgroup0_.property3 as conversion4_1_0_, assetgroup0_.property4 as target5_1_0_, assetgroup0_.property5 as accepted6_1_0_ from table2 assetgroup0_ where assetgroup0_.id=?

Thanks Allot,
Vitaliy


Top
 Profile  
 
 Post subject: Is this a bug??
PostPosted: Sun Jul 22, 2007 3:45 am 
Beginner
Beginner

Joined: Thu May 10, 2007 4:20 am
Posts: 27
I can't get it - why Hibernate won't update an object?
Any ideas how can I debug this?

Did I forget to post anything that might help??

Thanks,
Vitaliy


Top
 Profile  
 
 Post subject: updating composite id?
PostPosted: Sun Jul 22, 2007 5:49 am 
Beginner
Beginner

Joined: Thu May 10, 2007 4:20 am
Posts: 27
Hi,

I think that this behavior is due to my attempt to update a composite id.

If I move the property outside of a composite id declaration - it works fine.
The problem is that it should be part of a composite id...

Why shouldn't an update of a composite id work?

Thanks,
Vitaliy


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jul 22, 2007 6:02 am 
Beginner
Beginner

Joined: Thu May 10, 2007 4:20 am
Posts: 27
OK,
I think I'll post it in a new thread to make things clearer.


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