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: IBM JDK issues
PostPosted: Tue Mar 23, 2004 12:46 pm 
Beginner
Beginner

Joined: Mon Nov 10, 2003 7:09 pm
Posts: 28
I've been trying to get one of our applications that runs perfectly happily under the Sun 1.4 JVM (Tomcat) to IBM's JVM. Under the IBM 1.4 JVM (Websphere 5), I experience the following exception with proxies and .equals:

Code:
java.lang.IllegalArgumentException: object is not an instance of declaring class
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:79)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:41)
   at java.lang.reflect.Method.invoke(Method.java:386)
   at cirrus.hibernate.proxy.LazyInitializer.invoke(LazyInitializer.java:106)
   at cirrus.hibernate.proxy.CGLIBLazyInitializer.intercept(CGLIBLazyInitializer.java:46)
   at java.lang.Object$$EnhancedByCGLIB$$1.equals(<generated>)
   at com.ibm.ws.webcontainer.srt.SRTServletRequest.getAttribute(SRTServletRequest.java:1101)
   at com.cgc.WebUtils.moveAttributeFromSession(WebUtils.java:28)
   at com.cgc.collaborator.modules.directory.actions.LocationListAction.displayLocationsFrame(LocationListAction.java:54)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:79)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:41)
   at java.lang.reflect.Method.invoke(Method.java:386)
   at org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:280)
   at org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:216)
   at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
   at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
   at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1480)
   at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:506)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
   at com.ibm.ws.webcontainer.servlet.StrictServletInstance.doService(StrictServletInstance.java:110)
   at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet._service(StrictLifecycleServlet.java:174)
   at com.ibm.ws.webcontainer.servlet.IdleServletState.service(StrictLifecycleServlet.java:313)
   at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet.service(StrictLifecycleServlet.java:116)
   at com.ibm.ws.webcontainer.servlet.ServletInstance.service(ServletInstance.java:283)
   at com.ibm.ws.webcontainer.servlet.ValidServletReferenceState.dispatch(ValidServletReferenceState.java:42)
   at com.ibm.ws.webcontainer.servlet.ServletInstanceReference.dispatch(ServletInstanceReference.java:40)
   at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.handleWebAppDispatch(WebAppRequestDispatcher.java:974)
   at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.dispatch(WebAppRequestDispatcher.java:555)
   at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.forward(WebAppRequestDispatcher.java:200)
   at com.ibm.ws.webcontainer.srt.WebAppInvoker.doForward(WebAppInvoker.java:119)
   at com.ibm.ws.webcontainer.srt.WebAppInvoker.handleInvocationHook(WebAppInvoker.java:276)
   at com.ibm.ws.webcontainer.cache.invocation.CachedInvocation.handleInvocation(CachedInvocation.java:71)
   at com.ibm.ws.webcontainer.cache.invocation.CacheableInvocationContext.invoke(CacheableInvocationContext.java:114)
   at com.ibm.ws.webcontainer.srp.ServletRequestProcessor.dispatchByURI(ServletRequestProcessor.java:186)
   at com.ibm.ws.webcontainer.oselistener.OSEListenerDispatcher.service(OSEListener.java:334)
   at com.ibm.ws.webcontainer.http.HttpConnection.handleRequest(HttpConnection.java:56)
   at com.ibm.ws.http.HttpConnection.readAndHandleRequest(HttpConnection.java:618)
   at com.ibm.ws.http.HttpConnection.run(HttpConnection.java:443)
   at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:593)


This object being proxied does not override the equals method. I can workaround the problem simply enough by adding a trivial equals method. Clearly though, I don't want to have to do this, since the docs state:

Code:
Certain operations do not require proxy initialization

equals(), if the persistent class does not override equals()


Hibernate version: 1.2.5 (slightly customized to use CGLIB1.1 - 1.0 does not work with IBM JVM)
mapping for the class in question (abbreviated):
Code:
<class name="com.cgc.collaborator.directory.company.CompanyDirectoryEntryImpl" table="company_directory" proxy="com.cgc.collaborator.directory.company.CompanyDirectoryEntry">
        <id name="id" type="long" column="ID" unsaved-value="0">
            <generator class="hilo.long">
                <param>company_directory_id_gen</param>
                <param>next_hi</param>
            </generator>
        </id>
        <timestamp column="TIMESTAMP" name="modificationTime"/>
        <property name="name" column="name" type="string"/>
        <property name="type" column="type" type="string"/>
        <property name="womanOwned" column="woman_own" type="boolean"/>
        <property name="minorityOwned" column="minority_own" type="boolean"/>
        <property name="smallBusiness" column="small_bus" type="boolean"/>
        <property name="openShop" column="open_shop" type="boolean"/>
        <property name="distributeFax" column="dist_fax" type="boolean"/>
        <property name="distributePrint" column="dist_print" type="boolean"/>
        <property name="distributeEmail" column="dist_email" type="boolean"/>
        <bag role="contacts" cascade="all" lazy="true" readonly="true">
            <key column="company_directory_id"/>
            <one-to-many class="com.cgc.collaborator.directory.company.CompanyDirectoryEntryContact"/>
        </bag>
        <bag role="locations" cascade="all" lazy="true" readonly="true">
            <key column="company_directory_id"/>
            <one-to-many class="com.cgc.collaborator.directory.company.CompanyDirectoryEntryLocation"/>
        </bag>
        <!--<many-to-one name="defaultLocation" class="com.cgc.collaborator.directory.company.CompanyDirectoryEntryLocation" column="default_loc_id"/>
        <many-to-one name="defaultContact" class="com.cgc.collaborator.directory.company.CompanyDirectoryEntryContact" column="default_contact_id"/> -->
        <many-to-one name="company" class="com.cgc.collaborator.Company" column="company_id"/>       
    </class>


Any thoughts and suggestions are appreciated.

Ken


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 23, 2004 1:21 pm 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
"at sun.reflect.NativeMethodAccessorImpl" ...
Are you sure it is "Under the IBM 1.4 JVM (Websphere 5)" ? Some SUN
pre jdk 1.4.0 versions have problem with "Method.getDeclaringClass()".

BTW If you started to customize hibernate, you can strip all methods declared by object with cglib filter too.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 23, 2004 1:27 pm 
Beginner
Beginner

Joined: Mon Nov 10, 2003 7:09 pm
Posts: 28
Fairly sure that I'm running IBM's JDK. Here's whats reported at Websphere startup:
Code:
Java version = J2RE 1.4.1 IBM Windows 32 build cn1411-20031011 (JIT enabled: jitc), Java Compiler = jitc, Java VM name = Classic VM


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 23, 2004 2:05 pm 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
There is a workaround, but it is "slow":

CGLIBLazyInitializer.intercept(
Object proxy,
Method method,
MethodProxy mProxy,
Object[] args
)
{

Object obj = loadObject();

return obj.getClass().
getMethod(
method.getName(),
method.getParameterTypes()
).invoke(obj,args);

}


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 23, 2004 2:18 pm 
Beginner
Beginner

Joined: Mon Nov 10, 2003 7:09 pm
Posts: 28
Will that work under CGLIB1.1? I don't seem to have a loadObject() method available. Do I need to move to 2.0? Any other thoughts?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 23, 2004 2:32 pm 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
It is pseudo code to initialize proxy "Object obj = loadObject();", I do not remember code, but it must be some method to load object from DB.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 23, 2004 2:48 pm 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
I see this code in hibernate1 :

else if ( params==1 && !overridesEquals && "equals".equals(methodName) ) {
// less dodgy because Hibernate forces == to be same as identifier equals
return new Boolean( id.equals( getIdentifierMethod.invoke( args[0], null ) ) );
}


As I understand, cirrus.hibernate.proxy.LazyInitializer must return before
to load object and to invoke method if you do not override "equals".
I am afraid you will have more problems with reflection on this JVM.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 23, 2004 4:00 pm 
Beginner
Beginner

Joined: Mon Nov 10, 2003 7:09 pm
Posts: 28
Thanks for your help Juozas. I suppose as a workaround I'll always override equals with at least a trivial implementation, such as

public boolean equals(Object o) {
super.equals(o);
}

Any particular gotchas to this?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 23, 2004 7:23 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
This behavior was changed in Hibernate2, so an alternative is to upgrade...


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 23, 2004 8:01 pm 
Beginner
Beginner

Joined: Mon Nov 10, 2003 7:09 pm
Posts: 28
I'm really hoping not to have to upgrade since 1 & 2 aren't 100% compatible out of the box, and I don't truly have the time or the urge to rewrite our app.

Which behavior, specifically, has changed? The version of 1.2.5 I'm running now has essentially pulled in the code from the proxy package of Hibernate2. Is there some other bit of code from Hibernate2 I can refactor into Hibernate1 to make it work?

Thanks,
Ken


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 24, 2004 2:07 am 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
change this code in cirrus.hibernate.proxy.LazyInitializer.invoke()

else if ( params==1 && !overridesEquals && "equals".equals(methodName) ) {
// less dodgy because Hibernate forces == to be same as identifier equals
return new Boolean( id.equals( getIdentifierMethod.invoke( args[0], null ) ) );
}

to

else if ( params==1 /* && !overridesEquals*/ && "equals".equals(methodName) ) {
// less dodgy because Hibernate forces == to be same as identifier equals
return new Boolean( id.equals( getIdentifierMethod.invoke( args[0], null ) ) );
}

but it can be more problems.
Looks like
"cls.getDeclaredMethod(...).getDeclaringClass() == cls" is false on this JVM.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 21, 2005 10:53 am 
Newbie

Joined: Wed Aug 04, 2004 6:19 am
Posts: 9
ibm jdk 1.3.1 was difficult to find,
so i post the link here:

http://www-1.ibm.com/support/docview.ws ... wg24006479


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.