-->
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.  [ 12 posts ] 
Author Message
 Post subject: update and delete completes with no errors when it should
PostPosted: Sun Jul 17, 2005 10:59 pm 
Newbie

Joined: Thu Jul 14, 2005 4:39 am
Posts: 8
well.. since someone ranted..

Hibernate version: 2.1.8

Mapping documents:
<?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>


Code between sessionFactory.openSession() and session.close():
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();


Full stack trace of any exception that occurs: that's the problem.. none

Name and version of the database you are using:Oracle 8i

The generated SQL (show_sql=true):
Hibernate: update RTBEPAM.RTBEPAMAVAILABILITY set AVAILABILITY=?, REASON=? where IDENTITY1=? and IDENTITY2=?


Debug level Hibernate log excerpt: err.. im not sure where to get this

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

but based on documentation of the Session.update():
If the given transient instance has a null identifier, an exception will be thrown.
Quote:
...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.

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


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 18, 2005 6:07 am 
Expert
Expert

Joined: Tue Oct 05, 2004 9:45 am
Posts: 263
well, i'm using version 2.1.8, too and i'm getting an exception if i'm updating a row which doesn't exist ..

Set your log-level to "debug" (in the log4j.properties) and take a look what hibernate logs ...

Is it possible, that you have a bad exception-handling? E.g. a "try ... catch" which ignores the Hibernate-Exception?

HTH
curio


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 18, 2005 6:24 am 
Newbie

Joined: Thu Jul 14, 2005 4:39 am
Posts: 8
hello curio,

thanx for the attention. i do enclose it in a try/catch block but i throw a RemoteException with message coming from the exception that occured

Code:
try{
   //... the stated code above
   //do stuff here
}
catch(Exception ex){
   ex.printStackTrace();
   throw new RemoteException(ex.getMessage());
}


but still i see neither exceptions nor stacktrace.

with the log4j.properties set to debug.. this is still all ive got... i think i hve some config not yet set :P

Code:
Hibernate: update RTBEPAM.RTBEPAMAVAILABILITY set AVAILABILITY=?, REASON=? where IDENTITY1=? and IDENTITY2=?

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


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 18, 2005 7:59 am 
Expert
Expert

Joined: Tue Oct 05, 2004 9:45 am
Posts: 263
hi kgmanuel,

if you set the log-level to debug, hibernate logs the values which are set for the "?" ...
Then you can try the update-command with those values ...

Maybe your code to generate the id-values doesn't work as it should an the update will work due to 'wrong' id-settings ...

... and are you sure your "RemoteException" is handled right and are you sure you would see "e.printStackTrace" somewhere on the console or log?

gtx
curio


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 18, 2005 10:41 pm 
Newbie

Joined: Thu Jul 14, 2005 4:39 am
Posts: 8
curio wrote:
hi kgmanuel,

if you set the log-level to debug, hibernate logs the values which are set for the "?" ...
Then you can try the update-command with those values ...

Maybe your code to generate the id-values doesn't work as it should an the update will work due to 'wrong' id-settings ...

... and are you sure your "RemoteException" is handled right and are you sure you would see "e.printStackTrace" somewhere on the console or log?

gtx
curio


an earlier call to a select statement shows the values being used. while my problematic hql doesn't. i am still not sure what else to set in the log4j file

Code:
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
log4j.logger.net.sf.hibernate.type=debug
log4j.logger.net.sf.hibernate.ps.PreparedStatementCache=debug


the remote exception is handled right. and yes i do call the printStackTrace() and if an exception would be thrown it will be printed. (i intentionally placed an if (true){ throw new Exception("test");} and yes it printed out.)

Quote:
Maybe your code to generate the id-values doesn't work as it should


what did you mean by this. would this be on the mapping file or on the java code?

much thanx again for the time and attention :)

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


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 19, 2005 2:59 am 
Expert
Expert

Joined: Tue Oct 05, 2004 9:45 am
Posts: 263
hi kgmanuel,

you can try it with this log4j.properties - file:
Code:
# Log4J properties
log4j.rootLogger=DEBUG, CONSOLE, FILE
# CONSOLE appender
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern=%d %-5p [%t] %c{3} %x - %m%n
# FILE appender
log4j.appender.FILE=org.apache.log4j.RollingFileAppender
log4j.appender.FILE.File=!!!!YOUR LOG FILE-NAME!!!!!
log4j.appender.FILE.MaxFileSize=999KB
log4j.appender.FILE.MaxBackupIndex=1
log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
log4j.appender.FILE.layout.ConversionPattern=%d %-5p [%t] %c %x - %m%n


But don't forget to add a name for the log-file ;)

Then you can see what values hibernate uses ... this should make it a lot easier to find the problem ...

:) and now, just looking a second time over your code i found this:
Code:
session.update(availability);

Why don't you call "saveOrUpdate" or "save"? I must admit, that i don't know what's happening if you call the "update"-method and there's nothing to update ... but i'm quite sure an exception occurs ... but i'll try this case ...

BTW: If you have the possibility to use Primary-Keys with only one column ... do it. It's much easer to handle ...

gtx
curio


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 19, 2005 3:37 am 
Newbie

Joined: Thu Jul 14, 2005 4:39 am
Posts: 8
hello again curio,

thanx for the help. finally got the logger to work.. i have intentionally cleared a few of the details (timestamp, source thread/process, etc.). i just retained the dash to know if its a new line or continuation

Code:
- updating
- current autocommit status:false
- updating [net.telic.rtbec.pam.hibernate.Rtbepamavailability#net.telic.rtbec.pam.hibernate.Rtbepamavailability@1184a4f[identity1=2741,identity2=1]]
- commit
- flushing session
- Flushing entities and processing referenced collections
- Updating entity: [net.telic.rtbec.pam.hibernate.Rtbepamavailability#net.telic.rtbec.pam.hibernate.Rtbepamavailability@1184a4f[identity1=2741,identity2=1]]
- Processing unreferenced collections
- Scheduling collection removes/(re)creates/updates
- Flushed: 0 insertions, 1 updates, 0 deletions to 1 objects
- Flushed: 0 (re)creations, 0 updates, 0 removals to 0 collections
- listing entities:
- net.telic.rtbec.pam.hibernate.Rtbepamavailability{reason=testing, availability=1}
- executing flush
- Updating entity: [net.telic.rtbec.pam.hibernate.Rtbepamavailability#net.telic.rtbec.pam.hibernate.Rtbepamavailability@1184a4f[identity1=2741,identity2=1]]
- about to open: 0 open PreparedStatements, 0 open ResultSets
- update RTBEPAM.RTBEPAMAVAILABILITY set AVAILABILITY=?, REASON=? where IDENTITY1=? and IDENTITY2=?
- preparing statement
- Dehydrating entity: [net.telic.rtbec.pam.hibernate.Rtbepamavailability#net.telic.rtbec.pam.hibernate.Rtbepamavailability@1184a4f[identity1=2741,identity2=1]]
- binding '1' to parameter: 1
- binding 'testing' to parameter: 2
- binding '2741' to parameter: 3
- binding '1' to parameter: 4
- Adding to batch
- Executing batch size: 1
- success of batch update unknown: 0
- done closing: 0 open PreparedStatements, 0 open ResultSets
- closing statement
- post flush
- transaction completion
- flushing session
- Flushing entities and processing referenced collections
- Processing unreferenced collections
- Scheduling collection removes/(re)creates/updates
- Flushed: 0 insertions, 0 updates, 0 deletions to 1 objects
- Flushed: 0 (re)creations, 0 updates, 0 removals to 0 collections
- listing entities:
- net.telic.rtbec.pam.hibernate.Rtbepamavailability{reason=testing, availability=1}
- executing flush
- post flush


i need a compositeid coz i need to ensure that both exists and the combination is unique. im in telephony and technically, if i am already talking to you, i shouldnt be able to use the same number to call you again unless i hang up, ryt?

kinda odd that so many flush happened. i was expecting only two at most.

Code:
- Flushed: 0 insertions, 1 updates, 0 deletions to 1 objects
- Flushed: 0 (re)creations, 0 updates, 0 removals to 0 collections
...
...
- Flushed: 0 insertions, 0 updates, 0 deletions to 1 objects
- Flushed: 0 (re)creations, 0 updates, 0 removals to 0 collections


i guess this means that the latter did not succeed, but still did not throw any errors.

Code:
- current autocommit status:false
- updating [net.telic.rtbec.pam.hibernate.Rtbepamavailability#net.telic.rtbec.pam.hibernate.Rtbepamavailability@1184a4f[identity1=2741,identity2=1]]
...
...
- Dehydrating entity: [net.telic.rtbec.pam.hibernate.Rtbepamavailability#net.telic.rtbec.pam.hibernate.Rtbepamavailability@1184a4f[identity1=2741,identity2=1]]
- binding '1' to parameter: 1
- binding 'testing' to parameter: 2
- binding '2741' to parameter: 3
- binding '1' to parameter: 4
- Adding to batch
- Executing batch size: 1
- success of batch update unknown: 0


the bounded values are accurate. though i dont understand why an update is called so early. is it because i created an instance of Rtbepamavailability using 'new'? also, stating success of batch update unknown.... errr... ???

i do not use saveOrUpdate() because this would mean that if it does not exist, it would insert, ryt? i intend to keep those two separate (insert and update). for this method, i only intend to update. how did your test case went? did it throw exceptions?

much thanx again for the time and attention. i really appreciate the help :)

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


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 19, 2005 4:22 am 
Expert
Expert

Joined: Tue Oct 05, 2004 9:45 am
Posts: 263
hmmm ...

Code:
success of batch update unknown: 0

i think that's the problem ...

looking in the hibernate-sources i found this in BatchingBatcher.java line 58:
[code]if ( results[i]==-2 ) {
if ( log.isDebugEnabled() ) log.debug("success of batch update unknown: " + i);[code]

Have you tried using a different jdbc-driver? I'm not using a Oracle but 've read in this forum that there're some problems with 8i and the original Oracle jdbc-driver ... Perhaps try the 9i-driver?

I think the Problem why no exception is thrown is that the driver doesn't return the number of updated records ... it returns a "SUCCESS_NO_INFO". (look at java.sql.PreparedStatement.executeBatch - JavaDoc) The Problem is, that you're not getting an error if you try to update an entry which is not there ... my driver (db2) returns a "0" in this case for "nothing to update" ... then hibernate throws an exception because it expected that "1" entry was updated ...

gtx
curio


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 19, 2005 4:53 am 
Newbie

Joined: Thu Jul 14, 2005 4:39 am
Posts: 8
hi curio,

thanx again for spending time. :)

curio wrote:
Have you tried using a different jdbc-driver? I'm not using a Oracle but 've read in this forum that there're some problems with 8i and the original Oracle jdbc-driver ... Perhaps try the 9i-driver?


i already tried this issue with the 9i driver. never used the 8i. currently using a 10g driver, unless 10g has unresolved issues or new issues with regards to returning the updated entries... i dont think it should be the case..

curio wrote:
I think the Problem why no exception is thrown is that the driver doesn't return the number of updated records ... it returns a "SUCCESS_NO_INFO".


SUCCESS_NO_INFO equates to '-2'
the return of the query however is 0. this is using a direct query
Code:
PreparedStatement stmt = ru.getRtbeConnection().prepareStatement(sql);
stmt.setLong(1, 1);
stmt.setString(2, "testing");
stmt.setLong(3, 2741);
stmt.setLong(4, 1);
int result = stmt.executeUpdate();
d("result: " + result);


curio wrote:
The Problem is, that you're not getting an error if you try to update an entry which is not there ... my driver (db2) returns a "0" in this case for "nothing to update" ... then hibernate throws an exception because it expected that "1" entry was updated ...


hmm.. shouldn't hibernate throw or return some sort of equivalent? anyway, db2 driver?[/code]

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


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 19, 2005 5:03 am 
Expert
Expert

Joined: Tue Oct 05, 2004 9:45 am
Posts: 263
hi kgmanuel,

Quote:
SUCCESS_NO_INFO equates to '-2'

yes ... i've only found the statement "success of batch update unknown" as i've found in your logs in the BatchingBatcher if the return-value is "-2" ...

The difference to your example is, that hibernate uses a "batcher" and so calls the method "executeBatch" ... you're using the method "executeUpdate" at PreparedStatement ... so you're not testint the same method.

I'm not quite sure ... but i think you can disable using the "Batch-Mode" ...
try setting
Code:
hibernate.jdbc.batch.size
to "0" .. that should disable the use of the JDBC2-Batch-Updates ... your log-output should change ... maybe that solves your problem ...

But not using the Batch-Update may be a performance-problem ...

gtx
curio


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

Joined: Thu Jul 14, 2005 4:39 am
Posts: 8
hello again curio,

ill try to look up for how to disable the batch update of hibernate... though i think its rather unlikely...

so far.. yes the executeBatch of Statement does return a -2 value. though i was hoping hibernate would've thrown some better equivalent reaction.

atleast the problem is now narrowed down... if i end up not finding a way to disable this batch update... i might post on another thread. :)

thank you so much for your time curio :)

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


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 19, 2005 7:18 am 
Expert
Expert

Joined: Tue Oct 05, 2004 9:45 am
Posts: 263
hi kgmanuel,

no problem :)

hmmm ... i still can't belive that this won't work with the oracle-jdbc-driver ... strange ... really strange.
Perhaps it's a question of configuration? Sorry ... but i havn't used a Oracle with Hibernate/JDBC so far ...

gtx
curio


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