-->
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.  [ 8 posts ] 
Author Message
 Post subject: update does not work without errormessage
PostPosted: Thu Jul 14, 2005 4:40 am 
Newbie

Joined: Thu Jun 16, 2005 2:51 am
Posts: 12
Hello,

I want to update a detached Element(in a JBOSS Environment). That did not work without any errormessage.
So now I reload the element, and save it in the same session with the same result. I tried session.update too.

What could be the problem?

Hibernate version:

3.0.5

Mapping documents:

<?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="de.test.pps.VoAbteilung2" table="ABTEILUNG2" >
<meta attribute="class-description">Repräsentiert eine Abteilung in der Test Datenbank</meta>
<id name="voAbteilung2Key" column="dbKey" type="integer" length="4">
<generator class="native"></generator>
</id>
<natural-id>
<property name="mandant" type="integer" not-null="false" column="mandant" length="4" />
<property name="abteilungsnummer" type="integer" not-null="true" column="abteilungsnummer" length="4" />
</natural-id>

<version name="version" column="version"></version>
<property name="name" type="string" not-null="true" column="ABTEILUNGSNAME" length="20" />

</class>
<query name="de.test.pps.getMaxAbteilungsNummer">
<![CDATA[select max(abt.abteilungsnummer) from de.test.pps.VoAbteilung2 as abt where abt.mandant = :mandant]]>
</query>
</hibernate-mapping>


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

Session session = getSessionFactory().getCurrentSession();
tx=session.beginTransaction();
List abtList = session.createCriteria(VoAbteilung2.class).add(
Restrictions.eq("mandant", neu.getMandant())).add(
Restrictions.eq("abteilungsnummer", neu.getAbteilungsnummer())).list();

alt=(VoAbteilung2) abtList.get(0);
alt.setName(neu.getName());
session.save(alt);
tx.commit();
session.close();

Full stack trace of any exception that occurs:

Name and version of the database you are using:

HSQL 1.8.0 or Mysql 4.0.21

The generated SQL (show_sql=true):

Update 0: update ABTEILUNG2 set version=?, ABTEILUNGSNAME=? where dbKey=? and version=?

Debug level Hibernate log excerpt:

2005-07-14 10:27:07,854 DEBUG [org.hibernate.impl.SessionFactoryObjectFactory] JNDI lookup: hibernate/HibernateFactory2
2005-07-14 10:27:07,854 DEBUG [org.hibernate.impl.SessionFactoryObjectFactory] lookup: uid=4028821a05146b6d0105146b70490000
2005-07-14 10:27:07,854 DEBUG [org.hibernate.jdbc.JDBCContext] successfully registered Synchronization
2005-07-14 10:27:07,854 DEBUG [org.hibernate.impl.SessionImpl] opened session at timestamp: 4592966155689984
2005-07-14 10:27:07,925 DEBUG [org.hibernate.transaction.JTATransaction] begin
2005-07-14 10:27:07,925 DEBUG [org.hibernate.transaction.JTATransaction] Looking for UserTransaction under: UserTransaction
2005-07-14 10:27:07,925 DEBUG [org.hibernate.transaction.JTATransaction] Obtained UserTransaction
2005-07-14 10:27:07,925 DEBUG [org.hibernate.jdbc.AbstractBatcher] about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
2005-07-14 10:27:07,925 DEBUG [org.hibernate.jdbc.ConnectionManager] opening JDBC connection
2005-07-14 10:27:07,925 DEBUG [org.hibernate.SQL] select this_.dbKey as dbKey0_, this_.version as version0_0_, this_.mandant as mandant0_0_, this_.abteilungsnummer as abteilun4_0_0_, this_.ABTEILUNGSNAME as ABTEILUN5_0_0_ from ABTEILUNG2 this_ where this_.mandant=? and this_.abteilungsnummer=?
2005-07-14 10:27:07,925 INFO [STDOUT] Hibernate: select this_.dbKey as dbKey0_, this_.version as version0_0_, this_.mandant as mandant0_0_, this_.abteilungsnummer as abteilun4_0_0_, this_.ABTEILUNGSNAME as ABTEILUN5_0_0_ from ABTEILUNG2 this_ where this_.mandant=? and this_.abteilungsnummer=?
2005-07-14 10:27:07,925 DEBUG [org.hibernate.jdbc.AbstractBatcher] preparing statement
2005-07-14 10:27:07,925 DEBUG [org.hibernate.type.IntegerType] binding '1' to parameter: 1
2005-07-14 10:27:07,925 DEBUG [org.hibernate.type.IntegerType] binding '1' to parameter: 2
2005-07-14 10:27:07,925 DEBUG [org.hibernate.jdbc.AbstractBatcher] about to open ResultSet (open ResultSets: 0, globally: 0)
2005-07-14 10:27:07,925 DEBUG [org.hibernate.loader.Loader] processing result set
2005-07-14 10:27:07,925 DEBUG [org.hibernate.loader.Loader] result set row: 0
2005-07-14 10:27:07,925 DEBUG [org.hibernate.type.IntegerType] returning '1' as column: dbKey0_
2005-07-14 10:27:07,925 DEBUG [org.hibernate.loader.Loader] result row: EntityKey[de.test.pps.VoAbteilung2#1]
2005-07-14 10:27:07,925 DEBUG [org.hibernate.loader.Loader] Initializing object from ResultSet: [de.test.pps.VoAbteilung2#1]
2005-07-14 10:27:07,925 DEBUG [org.hibernate.persister.entity.BasicEntityPersister] Hydrating entity: [de.test.pps.VoAbteilung2#1]
2005-07-14 10:27:07,925 DEBUG [org.hibernate.type.IntegerType] returning '0' as column: version0_0_
2005-07-14 10:27:07,925 DEBUG [org.hibernate.type.IntegerType] returning '1' as column: mandant0_0_
2005-07-14 10:27:07,925 DEBUG [org.hibernate.type.IntegerType] returning '1' as column: abteilun4_0_0_
2005-07-14 10:27:07,925 DEBUG [org.hibernate.type.StringType] returning 'neu' as column: ABTEILUN5_0_0_
2005-07-14 10:27:07,925 DEBUG [org.hibernate.engine.TwoPhaseLoad] Version: 0
2005-07-14 10:27:07,925 DEBUG [org.hibernate.loader.Loader] done processing result set (1 rows)
2005-07-14 10:27:07,925 DEBUG [org.hibernate.jdbc.AbstractBatcher] about to close ResultSet (open ResultSets: 1, globally: 1)
2005-07-14 10:27:07,925 DEBUG [org.hibernate.jdbc.AbstractBatcher] about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
2005-07-14 10:27:07,925 DEBUG [org.hibernate.jdbc.AbstractBatcher] closing statement
2005-07-14 10:27:07,925 DEBUG [org.hibernate.jdbc.ConnectionManager] aggressively releasing JDBC connection
2005-07-14 10:27:07,925 DEBUG [org.hibernate.jdbc.ConnectionManager] closing JDBC connection [ (open PreparedStatements: 0, globally: 0) (open ResultSets: 0, globally: 0)]
2005-07-14 10:27:07,925 DEBUG [org.hibernate.loader.Loader] total objects hydrated: 1
2005-07-14 10:27:07,925 DEBUG [org.hibernate.engine.TwoPhaseLoad] resolving associations for [de.test.pps.VoAbteilung2#1]
2005-07-14 10:27:07,925 DEBUG [org.hibernate.engine.TwoPhaseLoad] done materializing entity [de.test.pps.VoAbteilung2#1]
2005-07-14 10:27:07,925 DEBUG [org.hibernate.engine.PersistenceContext] initializing non-lazy collections
2005-07-14 10:27:07,935 DEBUG [org.hibernate.event.def.DefaultSaveOrUpdateEventListener] ignoring persistent instance
2005-07-14 10:27:07,935 DEBUG [org.hibernate.event.def.DefaultSaveOrUpdateEventListener] object already associated with session: [de.test.pps.VoAbteilung2#1]
2005-07-14 10:27:07,935 DEBUG [org.hibernate.transaction.JTATransaction] commit
2005-07-14 10:27:07,935 DEBUG [org.hibernate.impl.SessionImpl] closing session
2005-07-14 10:27:07,935 DEBUG [org.hibernate.transaction.CacheSynchronization] transaction before completion callback
2005-07-14 10:27:07,935 DEBUG [org.hibernate.transaction.CacheSynchronization] automatically flushing session
2005-07-14 10:27:07,935 DEBUG [org.hibernate.impl.SessionImpl] automatically flushing session
2005-07-14 10:27:07,935 DEBUG [org.hibernate.jdbc.JDBCContext] before transaction completion
2005-07-14 10:27:07,935 DEBUG [org.hibernate.impl.SessionImpl] before transaction completion
2005-07-14 10:27:07,935 DEBUG [org.hibernate.transaction.CacheSynchronization] transaction after completion callback, status: 3
2005-07-14 10:27:07,935 DEBUG [org.hibernate.jdbc.JDBCContext] after transaction completion
2005-07-14 10:27:07,935 DEBUG [org.hibernate.impl.SessionImpl] after transaction completion


Top
 Profile  
 
 Post subject: similar issue.
PostPosted: Thu Jul 14, 2005 5:38 am 
Newbie

Joined: Thu Jul 14, 2005 4:39 am
Posts: 8
i have a table named: Rtbepamavailability
and currently has no contents.

then i made call like this
Code:
Rtbepamavailability availability = new Rtbepamavailability();
availability.setIdentity1(identity.getIdentityid());
availability.setIdentity2(identityid);
availability.setAvailability(availability1);
availability.setReason(reason);
      
Transaction tx = session.beginTransaction();
session.update(availability);
tx.commit();
session.flush();

webservice logs shows this:
Quote:
Hibernate: update RTBEPAM.RTBEPAMAVAILABILITY set AVAILABILITY=?, REASON=? where IDENTITY1=? and IDENTITY2=?

technically this call should fail since there is nothing to update.

but based on documentation of the Session.update():
Quote:
If the given transient instance has a null identifier, an exception will be thrown.

...it should throw an exception. or should i try to retrieve the data first before i update?

and since it returns a void, no way to know whether the change took effect or not.

i am using hibernate-2.1.8

please advise. much thanx in advance.

_________________
the pure and simple truth is never pure and rarely simple


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 14, 2005 5:41 am 
Newbie

Joined: Thu Jul 14, 2005 4:39 am
Posts: 8
forgot to include this.. sorry

hibernate file:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="net.telic.rtbec.pam.hibernate.Rtbepamavailability" table="RTBEPAMAVAILABILITY" schema="RTBEPAM">
<composite-id>
<key-property name="identity1" column="IDENTITY1" type="long" length="21"/>
<key-property name="identity2" column="IDENTITY2" type="long" length="21"/>
</composite-id>
<property name="availability" column="AVAILABILITY" type="long" length="10" not-null="true"/>
<property name="reason" column="REASON" type="string" length="256" not-null="true"/>
</class>
</hibernate-mapping>

_________________
the pure and simple truth is never pure and rarely simple


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 14, 2005 6:52 am 
Newbie

Joined: Thu Jun 16, 2005 2:51 am
Posts: 12
what do you think about using an own thread?

best regards


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 14, 2005 6:52 am 
Newbie

Joined: Thu Jun 16, 2005 2:51 am
Posts: 12
what do you think about using an own thread?

best regards


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 14, 2005 9:25 am 
Expert
Expert

Joined: Thu Jan 29, 2004 2:31 am
Posts: 362
Location: Switzerland, Bern
@maxwell:
Chagne your code to (without the session.save()):
Code:
Session session = getSessionFactory().getCurrentSession();
tx=session.beginTransaction();
List abtList = session.createCriteria(VoAbteilung2.class).add(
Restrictions.eq("mandant", neu.getMandant())).add(
Restrictions.eq("abteilungsnummer", neu.getAbteilungsnummer())).list();

alt=(VoAbteilung2) abtList.get(0);
alt.setName(neu.getName());
tx.commit();
session.close();


session.save() is used to save new instances. If you change an instance which is already known by the Session Hibernate triggers the update automatically.

HTH
Ernst


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 14, 2005 11:24 am 
Newbie

Joined: Thu Jun 16, 2005 2:51 am
Posts: 12
unfortunately with this change the update is not working yet.

Best regards


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 19, 2005 6:06 am 
Newbie

Joined: Thu Jun 16, 2005 2:51 am
Posts: 12
are additional informations missing or did i make a wrong posting?


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