-->
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.  [ 13 posts ] 
Author Message
 Post subject: Hibernate jars in client tier
PostPosted: Wed Feb 25, 2004 4:25 pm 
Beginner
Beginner

Joined: Thu Nov 06, 2003 10:04 pm
Posts: 22
I have come across an issue where I am finding myself the need to include hibernate jars (specifically hibernate2.jar and odmg.jar) in the client tier jars. The reason is this.

Since I have a rather complex object hierarchy in my J2EE environment, I am using my business classes themselves as the ones that are mapped for Hibernate to persist. And they are also being sent across to remote clients for viewing in a GUI.

Now in some of the business classes, there are collections which have been specified as java.util.List. Hibernate I understand sometimes replaces those List collections with net.sf.hibernate.List implementations. So when those business classse with those List collections get to the client side, I am getting ClassNotFoundException if I donot have the hibernate jars on the client classpath.

I wanted to know if anyone has any ideas to cleanly resolve this, or if I am stuck with having to include those jars to send to the client. Ofcourse the better solution is to convert the complex business objects to more simpler data transfer objects and send those to the client. But I wanted to find out if what I described is a common scenario and if there are any solutions.

Thanks
Rama


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 25, 2004 6:14 pm 
Expert
Expert

Joined: Sat Jan 17, 2004 2:57 pm
Posts: 329
Location: In the basement in my underwear
Well, you are not alone. We too have encountered the same scenario and are simply putting the required .jar files on the client.

Your suggestion of 'replacing' the hibernate implementation of list with say, for example, an ArrayList is all fine on the surface. However, bear in mind that the hibernate implementations for collections keep track of state for the sake of performing cascading operations. Simply replacing those lists would break that horribly I would think.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 25, 2004 8:18 pm 
Expert
Expert

Joined: Thu Jan 08, 2004 6:17 pm
Posts: 278
No, the Hibernate collections are safe to serialize to the client side. Since the client side has no session anyway, the collections' lazy loading state does not need to be preserved.

I think the only real answer to the problem of exposing the client to business classes or persistence classes that they shouldn't really see is to do some kind of DTO mapping to plain data classes without Hibernate or business-logic code.

This post (in a long thread about all these issues) outlines one hbm2java extension to make it at least easier to create the basic POJOs themselves, and then writing the generic DTO converter is at least possible without needing any further code generation. (Still hope to put my money where my mouth is on that....)

Cheers,
Rob


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 25, 2004 8:22 pm 
Expert
Expert

Joined: Thu Jan 08, 2004 6:17 pm
Posts: 278
...And since the collections' lazy loading state does not need to be preserved, it is safe to change the collections altogether from Hibernate collections to java.util collections.

(Though see this thread discussing the problems when you save a (cascaded) object graph that uses getID() for equals() and hashCode(), and that has been (partially) stored in hashed collections before being saved....)

Cheers!
Rob


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 26, 2004 2:16 pm 
Beginner
Beginner

Joined: Thu Nov 06, 2003 10:04 pm
Posts: 22
So are you saying other than using some kind of DTO mapping to our business objects, no one has found a better solution. I really donot like the idea of having to maintain two almost identical class hierarchies, one for the business/domain classes and one for their DTO equivalents. And especially I donot like the idea of having to replace hibernate specific collection implementations in the DTO instances everytime I do persistence related work.

If the answer is that we have to include hibernate jars, is there a minimal jar in hibernate bundle that can be sent to the client that just includes the basic types of hibernate. Is this a feasible idea?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 26, 2004 2:19 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
There is no minimal JAR. You only need the hibernate2.jar and cglib2.jar (about 1 MB) on the client to successfully deserialize a detached object graph. It's not perfect, but it might be OK for a Webstart/static installation in a LAN.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 26, 2004 3:09 pm 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
I am not sure it will work, but
It must be possible to serialize collections as standard implementations and proxies as original objects traspariently (replace in "writeReplace" method). Doe's somebody tried it ?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 26, 2004 3:55 pm 
Beginner
Beginner

Joined: Thu Nov 06, 2003 10:04 pm
Posts: 22
Can you please explain what you mean by "replace in "writeReplace" method"? I am not sure I understood your point.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 26, 2004 4:20 pm 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
"writeReplace" method is specified in java serialization. I am not sure it is a good idea, but it is possible to serialize collection this way:

"Serializable classes that need to designate an alternative object to be used when writing an object to the stream should implement this special method with the exact signature:

ANY-ACCESS-MODIFIER Object writeReplace() throws ObjectStreamException;
"

class MyCollection extends AbstractCollection implements Serializable{

Object writeReplace(){

return new ArrayList(this);

}


}

Serialization will put ArrayList to stream not instance of MyCollection and
ArrayList will be deserialized on client side. It is possible to test


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 01, 2004 11:41 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Note that all-delete-orphanj won't work this way. collection state is keep in Hibernate collection implementation

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 01, 2004 5:59 pm 
Beginner
Beginner

Joined: Thu Nov 06, 2003 10:04 pm
Posts: 22
So the solution to this is either use DTO mechanism or send hibernate jars to the client? Is that correct?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 01, 2004 6:25 pm 
Expert
Expert

Joined: Thu Jan 08, 2004 6:17 pm
Posts: 278
Yes, that's correct.


Top
 Profile  
 
 Post subject: Mismatched Serialization problem
PostPosted: Tue Feb 01, 2005 10:14 am 
Newbie

Joined: Sun Oct 03, 2004 9:00 am
Posts: 7
I was experiencing the same problem and it solved when i copied odmg-3.0.jar, hibernate2.jar and cgi-full.lib.jar.

However, I am facing the Mismatched Serialization UIDs problem in my Eclipse RCP. All Java VM arguments are same in stande alone and Eclipse RCP. Following is the stack trace of this exception:

java.rmi.MarshalException: CORBA MARSHAL 1229125786 No; nested exception is:
org.omg.CORBA.MARSHAL: Unable to read value from underlying bridge : Mismatched serialization UIDs : Source (Rep. IDRMI:java.util.HashMap:86573568A211C011:0507DAC1C31660D1) = 0507DAC1C31660D1 whereas Target (Rep. ID RMI:dash.hms.common.bo.ServiceCategory:ED162ABB6FFDC0FF:45A41691EA4BC44E) = 45A41691EA4BC44E vmcid: 0x4942f000 minor code: 2202 completed: No
at com.sun.corba.se.impl.javax.rmi.CORBA.Util.mapSystemException(Util.java:197)
at javax.rmi.CORBA.Util.mapSystemException(Util.java:67)
at dash.hms.client._SetupService_Stub.getServiceCategory(_SetupService_Stub.java:772)
at dash.hms.ui.HMSPlugin.start(HMSPlugin.java:70)
at org.eclipse.osgi.framework.internal.core.BundleContextImpl$1.run(BundleContextImpl.java:958)
at java.security.AccessController.doPrivileged(Native Method)
at org.eclipse.osgi.framework.internal.core.BundleContextImpl.startActivator(BundleContextImpl.java:954)
at org.eclipse.osgi.framework.internal.core.BundleContextImpl.start(BundleContextImpl.java:937)
at org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:417)
at org.eclipse.osgi.framework.internal.core.AbstractBundle.start(AbstractBundle.java:293)
at org.eclipse.core.runtime.adaptor.EclipseClassLoader.findLocalClass(EclipseClassLoader.java:110)
at org.eclipse.osgi.framework.internal.core.BundleLoader.findLocalClass(BundleLoader.java:371)
at org.eclipse.osgi.framework.internal.core.BundleLoader.findClass(BundleLoader.java:402)
at org.eclipse.osgi.framework.adaptor.core.AbstractClassLoader.loadClass(AbstractClassLoader.java:93)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at org.eclipse.osgi.framework.internal.core.BundleLoader.loadClass(BundleLoader.java:307)
at org.eclipse.osgi.framework.internal.core.BundleHost.loadClass(BundleHost.java:332)
at org.eclipse.osgi.framework.internal.core.AbstractBundle.loadClass(AbstractBundle.java:1315)
at org.eclipse.core.internal.registry.ConfigurationElement.createExecutableExtension(ConfigurationElement.java:161)
at org.eclipse.core.internal.registry.ConfigurationElement.createExecutableExtension(ConfigurationElement.java:151)
at org.eclipse.core.internal.registry.ConfigurationElement.createExecutableExtension(ConfigurationElement.java:138)
at org.eclipse.core.internal.registry.ConfigurationElementHandle.createExecutableExtension(ConfigurationElementHandle.java:48)
at org.eclipse.core.internal.runtime.PlatformActivator$1.run(PlatformActivator.java:216)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:273)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:129)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.eclipse.core.launcher.Main.basicRun(Main.java:185)
at org.eclipse.core.launcher.Main.run(Main.java:710)
at org.eclipse.core.launcher.Main.main(Main.java:694)
Caused by: org.omg.CORBA.MARSHAL: Unable to read value from underlying bridge : Mismatched serialization UIDs : Source (Rep. IDRMI:java.util.HashMap:86573568A211C011:0507DAC1C31660D1) = 0507DAC1C31660D1 whereas Target (Rep. ID RMI:dash.hms.common.bo.ServiceCategory:ED162ABB6FFDC0FF:45A41691EA4BC44E) = 45A41691EA4BC44E vmcid: 0x4942f000 minor code: 2202 completed: No
at com.ibm.rmi.iiop.CDRInputStream.read_value(CDRInputStream.java:1745)
at dash.hms.client._SetupService_Stub.getServiceCategory(_SetupService_Stub.java:761)
... 29 more


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