-->
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: hbm2java generates unusable toString methods for OSCache
PostPosted: Sat Sep 25, 2004 4:19 am 
Newbie

Joined: Fri Sep 24, 2004 1:24 pm
Posts: 5
A consultant company is developing a new application with Hibernate, Spring Framework and OSCache for us. The selection of these tools had been made by different reasons. We have some performance issues and investigated them.

Our logs are showing a lot of cache misses like
Quote:
com.mycompany.app.document.DocumentTypeInternationalPK@10cfd8[documentType=com.mycompany.app.document.DocumentTypeBO@358d27[docTypeId=18],language=com.mycompany.app.document.LanguageBO@de77cd[lanId=EN]].com.mycompany.app.document.DocumentTypeInternationalBO


The reason of the cache misses are the object ids: @10cfd8, @358d27, ...

Each time Hibernate checks if an object is in the cache, it will generate a new object with a different object id. Hence hibernate / OSCache is not possible to find the object in the cache, because OSCache must have well-behaved toString methods.

The objects ids are created by the toString method in the hbm2java generated java source files (BasicRenderer). Example:
Quote:
public String toString() {
return new ToStringBuilder(this)
.append("comId", getComId())
.append("keyword", getKeyword())
.toString();
}


hbm2java uses the Apache Commons ToStringBuilder to create the return strings of the toString method. The class ToStringBuilder uses the ToStringStyle.DEFAULT_STYLE by default. In the DEFAULT_STYLE the attribute useIdentityHashCode is set to true, hence the object ids are containing f.i. "@10cfd8". It is necessary to create a hibernate to string style:
Quote:
public static final HIBERNATE_TO_STRING_STYLE = new StandardToStringStyle() {
public StandardToStringStyle() {
super();
setUseIdentityHashCode(false);
}
};


Changing the line
Quote:
return new ToStringBuilder(this)

to
Quote:
return new ToStringBuilder(this, HIBERNATE_TO_STRING_STYLE)

should fix the problem.

I don't think this is a problem of OSCache, because it's behaviour is by design. OK, other cache implementation uses the hashcode and the equals methods to differentiate between different cache objects. I think the problem should be fixed in the code generation of hbm2java, because it it the easiest way to fix it and some other caches may ran into the same problem.

    Who ran into the same problem also? / Can somebody confirm this problem?
    Should I contact the developers of hbm2java to fix the problem in BasicRenderer?
    Should I raise an issue in JIRA?

http://www.opensymphony.com/oscache/hibernate.html
see "NOTE: object identifiers must have well-behaved toString() methods."

Hibernate version: 2.1
Hibernate extensions: 2.1.2[/quote]


Top
 Profile  
 
 Post subject:
PostPosted: Sat Sep 25, 2004 10:46 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
the correct way will be through JIRA - especially one with a patch ;)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: composite identifiers
PostPosted: Sun Sep 26, 2004 7:50 am 
Newbie

Joined: Fri Sep 24, 2004 1:24 pm
Posts: 5
Mathias wrote me that the unusable toString methods problem turn up only by composite identifiers.

We have a database model with a lot of tables and we are often using foreign keys and contrains. The database model was designed first. Followed by the usage of Middlegen. Therefore I think we have many composite identifiers.

Looking at my hit and miss logs I see the following well-behaved cache keys:
Code:
   5096.com.mycompany.app.master.KeywordBO.countries
   5096.com.mycompany.app.master.KeywordBO.indics
These are not composite identifiers.

At present I do not know why are only composite identifiers affected by the not well-behaved toString methods in Hibernate.


Top
 Profile  
 
 Post subject: JIRA issue
PostPosted: Sun Sep 26, 2004 8:46 am 
Newbie

Joined: Fri Sep 24, 2004 1:24 pm
Posts: 5
I raised a JIRA issue: http://opensource.atlassian.com/projects/hibernate/browse/HBX-19


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.