-->
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.  [ 7 posts ] 
Author Message
 Post subject: unmarshaling collection
PostPosted: Tue Aug 08, 2006 9:07 am 
Newbie

Joined: Tue Aug 08, 2006 8:56 am
Posts: 4
Hi, I have folowing problem: I have client JavaWS application and server, when I pass a collection to client via RMI I have exception:

java.lang.ClassNotFoundException: org.hibernate.collection.PersistentSet
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)

I think this because objects in the collection is proxied, if I do folowing all is all is right:

List<ValueScope> allVisible = dao.getAllVisible();
List<ValueScope> all = new ArrayList<ValueScope>();
for(ValueScope vs : allVisible)
all.add((ValueScope)vs.getPlainCopy());
return all;

can I turn of proxing in hibernate, or I must return plain copy in all bethods of business objects that return data.

I don't want include hibernate to the client because size is very important


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 08, 2006 9:14 am 
Expert
Expert

Joined: Tue Apr 25, 2006 12:04 pm
Posts: 260
Before closing hibernate session, load all your collection objects by calling Hibernate.initialize( dao.getAllVisible() )

I guess, with this your problem should be solved.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 08, 2006 9:35 am 
Newbie

Joined: Tue Aug 08, 2006 8:56 am
Posts: 4
No, I add this:

Hibernate.initialize(allVisible);
return allVisible;
and nothing happend, I can wright a method that will do the getPlainCopy() for all objects in collection, but maybe we can configure hibernate to return plain objects?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 08, 2006 9:56 am 
Expert
Expert

Joined: Tue Apr 25, 2006 12:04 pm
Posts: 260
I suppose by configuring you mean modifying your mapping files. If that is so, using the attribute lazy="false" on the collection element will load required objects without the necessity to call again Hibernate.initialize()


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 08, 2006 10:39 am 
Newbie

Joined: Tue Aug 08, 2006 8:56 am
Posts: 4
No, i include lazy=false, but objects is proxied anyway


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 25, 2007 11:24 pm 
Beginner
Beginner

Joined: Sat Dec 16, 2006 1:52 pm
Posts: 40
Did you solve this? I have the same issue.


Top
 Profile  
 
 Post subject: Yes, but the solution is not so good as I expect
PostPosted: Fri Jan 26, 2007 4:52 am 
Newbie

Joined: Tue Aug 08, 2006 8:56 am
Posts: 4
I add getPlainCopy (as member of AbstractDataObject.class ) method to each DTO object example:

public class Country extends AbstractDataObject {
private transient Country plainData;
private String id;
private Region region;
private String englishName;
private String alpha3Code;
private String countryCode;


public String getId() {
return this.id;
}

public void setId(String id) {
this.id = id;
}

public Region getRegion() {
return region;
}

public void setRegion(Region region) {
this.region = region;
}

public String getEnglishName() {
return englishName;
}

public void setEnglishName(String englishName) {
this.englishName = englishName;
}

public String getAlpha3Code() {
return alpha3Code;
}

public void setAlpha3Code(String alpha3Code) {
this.alpha3Code = alpha3Code;
}

public String getCountryCode() {
return countryCode;
}

public void setCountryCode(String countryCode) {
this.countryCode = countryCode;
}

public AbstractDataObject getPlainCopy() {
if (plainData == null) {
plainData = new Country();
plainData.setId(id);
if (region != null) {
plainData.setRegion((Region) region.getPlainCopy());
}
plainData.setEnglishName(englishName);
plainData.setAlpha3Code(alpha3Code);
plainData.setCountryCode(countryCode);
}
return plainData;
}
}

and then add invocation executor to our RMI subsystem:

public class RemoteRemoveProxyInvocationExecutor implements RemoteInvocationExecutor {
private Log log = LogFactory.getLog(getClass());

public Object invoke(RemoteInvocation remoteInvocation, Object object) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {

Object result;
try {
result = remoteInvocation.invoke(object);
/* CHECKSTYLE:OFF */
} catch (Throwable e) {
/* CHECKSTYLE:ON */
Throwable causeEx = e.getCause();
String mes;
mes = "Exception class: " + causeEx.getClass() + " (message: " + causeEx.getMessage() + ")";
log.error("Exception were thrown: ", e);
throw new ServerException(mes);
}
return getPlainData(result);

}

private Object getPlainData(Object o) {

if (o instanceof AbstractDataObject) {
return ((AbstractDataObject) o).getPlainCopy();
}

if (o instanceof Collection) {
if (!((Collection) o).isEmpty()) {
Collection returnCollection;
try {
returnCollection = (Collection) o.getClass().newInstance();
} catch (InstantiationException e) {
e.printStackTrace();
return o;
} catch (IllegalAccessException e) {
e.printStackTrace();
return o;
}
for (Object obj : (Collection) o) {
returnCollection.add(getPlainData(obj));
}
return returnCollection;
}
}
return o;
}
}

all seems to be fine now.


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