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