-->
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: Hibernate with webservice problems
PostPosted: Wed Oct 08, 2003 1:06 am 
Newbie

Joined: Wed Oct 08, 2003 12:00 am
Posts: 7
Hi

I'm using Hibernate as the core of a webservice designed to wrap up a database, and expose it to several clients written in .NET and java. Generally it has gone smoothly, however there are two problems, I was hoping somebody could help me find a solution to.

Firstly, the java collection classes can not be sent out via a webservice, if we want to be able to access the service via .NET. So, everywhere in the public interface of the webservice that I would like to have a List or a Set I'm forced to use arrays. This is a problem because Hibernate can only map bag's to Lists or Sets. To workaround the problem I have to convert my lists to arrays whenever I want the webservice to make use of them:
Code:
public Task[] getTasks()
{
   return (Task[])taskList.toArray(new Task[0]);
}

public void setTasks(Task[] tasks)
{
   setTaskList(new ArrayList(Arrays.asList(tasks)));
}


Is it possible / feasible to modify Hibernate to map bags to arrays? Where would I start looking in the source to make that modification?

Secondly because I use Hibernate to retrieve and update objects that will then be transmitted by the webservice Hibernate will alway throw "Another object was associated with this id". For example my webservice has the interface:
Code:
   public Employee[] getEmployees();
   public void updateEmployee(Employee toUpdate);


Now updateEmployee will alway give errors inside updateEmployee because Employee toUpdate is always going to be a new instance of Employee, as it is constructed from XML sent into the webservice. So far I have been able to work around the problem, by putting code like:
Code:
         
Object instance = session.load(Employee.class, new Integer(toUpdate.getID()));
session.evict(instance);

inside most of my methods, but this is really a pain when you have objects that are in turn composed of many other persistent objects. Is there anyway to work around this problem?

- Luke


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 08, 2003 1:45 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Not sure how helpfull this is, Hibernate 2.1 has an experimental XML data binder for converting between XML and POJOs. Its not documented but it is a part of the system. The other issue sounds like you have the long running session problem even though I assume you are making the RCP call within the context of the active session. Maybe you can disconnect the session, make RPC call then reconnect the session. This is similar to an approach for keeping a session between HTTP requests. Otherwise evicting will have to do.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 08, 2003 7:39 am 
Newbie

Joined: Sun Oct 05, 2003 4:29 pm
Posts: 14
Location: Toronto, Canada
On the updating issue, your Employee toUpdate has an internal id associated with it? If so, call session.saveOrUpdate(object). I'm pretty sure that will solve your problem.

John


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 10, 2003 1:48 am 
Newbie

Joined: Wed Oct 08, 2003 12:00 am
Posts: 7
Hey, thanks for your help!

The experemtal XML binder sounds intresting, however it sounds a little bit to experemental currently for our needs. How long I should keep the session running for is something I am unsure about. Currently I use the HibernateSession object described in the Thread Local Session pattern. This seems to keep sessions around for a long time. I've tried explicitly closing and opening a session inside each of the methods made avaliable as a webservice, however this seems to slow things down alot, as I imagine this causes a new connection to be made to the database each time start up the session.

Also, is it feasable to add Array in as a mapping for Bag. Where would I start looking to make such a modification.

As for calling session.saveOrUpdate(object) If I do so, Hibernate will throw "Another object was associated with this id" as the instance of object that was returned to the webservice client is different from the instance that was passed back in as a paramiter for saveOrUpdate.

Thanks alot for you help, and quick response
- Luke


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.