-->
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: version incrementing even on read-only usecase.
PostPosted: Wed Feb 28, 2007 10:42 am 
Newbie

Joined: Wed Feb 28, 2007 1:34 am
Posts: 1
I am having an issue with version increment. There is a Contact entity which has a char[] password field, String userName and Integer version.
I am just reading contact entity from database for a password check.
None of the fields are updated in the usecase. But hibernate increments
version number at the end of the transaction.

I tried to debug into hibernate source and this is what i observed,

TypeFactory.findDirty() method is called before commiting the transaction.

NullableType.isEquals(x,y) is called to compare the char[] pwd values.

EqualsHelper.equals(Object x, Object y) is called.

this equals method is implemented as follows,

public static boolean equals(Object x, Object y) {
return x==y || ( x!=null && y!=null && x.equals(y) );
}

This method will never return equal for two char[] Objects.

The solution will be to implement correct equals method in CharArrayType.

Has anyone reported this issue earlier?

Hibernate version:hibernate-3.2

Mapping documents:

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

Query q = em.createNamedQuery("Contact.findByUsername");
q.setParameter("username", username);

contact = (Contact)q.getSingleResult();

if (AppUtil.isValidPwd(contact.getPassword(), enteredPwd)
{
return contact;
}


Full stack trace of any exception that occurs: there is no exception

Name and version of the database you are using:JavaDB which comes with glassfish

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:
19:52:12,375 DEBUG QueryParameters:277 - named parameters: {username=unnisworld}
19:52:12,375 DEBUG AbstractBatcher:358 - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
19:52:12,390 DEBUG ConnectionManager:419 - opening JDBC connection
19:52:12,390 DEBUG SQL:393 - select contact0_.id as id88_, contact0_.version as version88_, contact0_.password as password88_, contact0_.username as username88_ from Contact contact0_ where contact0_.username=?
Hibernate: select contact0_.id as id88_, contact0_.version as version88_, contact0_.password as password88_, contact0_.username as username88_ from Contact contact0_ where contact0_.username=?
19:52:12,390 DEBUG AbstractBatcher:476 - preparing statement
19:52:12,500 DEBUG StringType:133 - binding 'unnisworld' to parameter: 1
19:52:12,515 DEBUG AbstractBatcher:374 - about to open ResultSet (open ResultSets: 0, globally: 0)
19:52:12,515 DEBUG Loader:682 - processing result set
19:52:12,515 DEBUG Loader:687 - result set row: 0
19:52:12,515 DEBUG LongType:172 - returning '1' as column: id88_
19:52:12,515 DEBUG Loader:1164 - result row: EntityKey[com.toolcafe.smash.model.Contact#1]
19:52:12,515 DEBUG Loader:1346 - Initializing object from ResultSet: [com.toolcafe.smash.model.Contact#1]
19:52:12,546 DEBUG AbstractEntityPersister:2027 - Hydrating entity: [com.toolcafe.smash.model.Contact#1]
19:52:12,546 DEBUG IntegerType:172 - returning '25' as column: version88_
19:52:12,546 DEBUG CharArrayType:172 - returning 'test123' as column: password88_
19:52:12,546 DEBUG StringType:172 - returning 'unnisworld' as column: username88_
19:52:12,578 DEBUG TwoPhaseLoad:75 - Version: 25
19:52:12,578 DEBUG Loader:709 - done processing result set (1 rows)
19:52:12,578 DEBUG AbstractBatcher:381 - about to close ResultSet (open ResultSets: 1, globally: 1)
19:52:12,578 DEBUG AbstractBatcher:366 - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
19:52:12,578 DEBUG AbstractBatcher:525 - closing statement
19:52:12,578 DEBUG ConnectionManager:402 - aggressively releasing JDBC connection
19:52:12,578 DEBUG ConnectionManager:439 - releasing JDBC connection [ (open PreparedStatements: 0, globally: 0) (open ResultSets: 0, globally: 0)]
19:52:12,578 DEBUG Loader:839 - total objects hydrated: 1
19:52:12,578 DEBUG TwoPhaseLoad:107 - resolving associations for [com.toolcafe.smash.model.Contact#1]
19:52:12,593 DEBUG TwoPhaseLoad:206 - done materializing entity [com.toolcafe.smash.model.Contact#1]
19:52:12,593 DEBUG StatefulPersistenceContext:777 - initializing non-lazy collections
19:58:34,593 DEBUG CacheSynchronization:40 - transaction before completion callback
19:58:34,593 DEBUG JDBCContext:201 - before transaction completion
19:58:34,593 DEBUG SessionImpl:393 - before transaction completion
19:58:34,593 DEBUG AbstractEntityManagerImpl:514 - automatically flushing session
19:58:34,593 DEBUG SessionImpl:337 - automatically flushing session
19:58:34,593 DEBUG AbstractFlushingEventListener:58 - flushing session
19:58:34,671 DEBUG AbstractFlushingEventListener:111 - processing flush-time cascades
19:58:34,671 DEBUG Cascade:115 - processing cascade ACTION_PERSIST_ON_FLUSH for: com.toolcafe.smash.model.Contact
19:58:34,671 DEBUG Cascade:150 - done processing cascade ACTION_PERSIST_ON_FLUSH for: com.toolcafe.smash.model.Contact
19:58:34,671 DEBUG AbstractFlushingEventListener:154 - dirty checking collections
19:58:34,671 DEBUG AbstractFlushingEventListener:171 - Flushing entities and processing referenced collections
20:01:11,921 DEBUG AbstractEntityPersister:3177 - com.toolcafe.smash.model.Contact.password is dirty
20:01:11,921 DEBUG DefaultFlushEntityEventListener:229 - Updating entity: [com.toolcafe.smash.model.Contact#1]
20:01:15,093 DEBUG Versioning:110 - Incrementing: 25 to 26
20:01:15,140 DEBUG AbstractFlushingEventListener:210 - Processing unreferenced collections
20:01:15,140 DEBUG AbstractFlushingEventListener:224 - Scheduling collection removes/(re)creates/updates
20:01:15,140 DEBUG AbstractFlushingEventListener:85 - Flushed: 0 insertions, 1 updates, 0 deletions to 1 objects
20:01:15,140 DEBUG AbstractFlushingEventListener:91 - Flushed: 0 (re)creations, 0 updates, 0 removals to 0 collections
20:01:15,140 DEBUG Printer:83 - listing entities:
20:01:15,140 DEBUG Printer:90 - com.toolcafe.smash.model.Contact{id=1, username=unnisworld, password=test123, version=25}
20:01:15,140 DEBUG AbstractFlushingEventListener:290 - executing flush
20:01:15,140 DEBUG ConnectionManager:467 - registering flush begin
20:01:15,156 DEBUG AbstractEntityPersister:2335 - Updating entity: [com.toolcafe.smash.model.Contact#1]
20:01:15,156 DEBUG AbstractEntityPersister:2337 - Existing version: 25 -> New version: 26
20:01:15,156 DEBUG AbstractBatcher:358 - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
20:01:15,156 DEBUG ConnectionManager:419 - opening JDBC connection
20:01:15,156 DEBUG SQL:393 - update Contact set version=?, password=?, username=? where id=? and version=?
Hibernate: update Contact set version=?, password=?, username=? where id=? and version=?
20:01:15,171 DEBUG AbstractBatcher:476 - preparing statement
20:01:15,328 DEBUG AbstractEntityPersister:1988 - Dehydrating entity: [com.toolcafe.smash.model.Contact#1]
20:01:15,328 DEBUG IntegerType:133 - binding '26' to parameter: 1
20:01:15,328 DEBUG CharArrayType:133 - binding 'test123' to parameter: 2
20:01:15,343 DEBUG StringType:133 - binding 'unnisworld' to parameter: 3
20:01:15,343 DEBUG LongType:133 - binding '1' to parameter: 4
20:01:15,343 DEBUG IntegerType:133 - binding '25' to parameter: 5
20:01:15,406 DEBUG AbstractBatcher:366 - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
20:01:15,406 DEBUG AbstractBatcher:525 - closing statement
20:01:15,406 DEBUG ConnectionManager:270 - skipping aggressive-release due to flush cycle
20:01:15,406 DEBUG ConnectionManager:476 - registering flush end
20:01:15,406 DEBUG ConnectionManager:402 - aggressively releasing JDBC connection
20:01:15,406 DEBUG ConnectionManager:439 - releasing JDBC connection [ (open PreparedStatements: 0, globally: 0) (open ResultSets: 0, globally: 0)]
20:01:15,421 DEBUG AbstractFlushingEventListener:321 - post flush
20:01:15,437 DEBUG CacheSynchronization:82 - transaction after completion callback, status: 3
20:01:15,437 DEBUG JDBCContext:215 - after transaction completion
20:01:15,437 DEBUG SessionImpl:422 - after transaction completion



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.