Wow! Sombody else using hibernate with web services!
I'm implementing a web services wrapper for a legacy DB with with Hibernate, apache Axis, and Tomcat. I would imagine that we will run across most of the same problems. I've already ran into the exact same problem with arrays.
Basically what I found was that hibernate arrays are pretty useless for what we need. This is because to use arrays your table actually needs a column which provides the index of your object in the array. The issue is discussed at:
http://www.hibernate.org/117.html#A5
What I basically had to do was have two sets of methods. A private getter and setter which took lists and were mapped via hibernate. And a public getter and setter which would be used by the web services. Using your example:
Code:
public class Cat
{
private Cat mommy;
private List toyList;
private List getToyList()
{ .... }
private void setToyList(List toyList)
{ ....}
public Toy[] getToys()
{
return (Toy[])toyList.toArray(new Toy[0]);
}
public void setToys(Toy[] newToys)
{
toyList = Arrays.asList(newToys);
}
}
Then map toyList as a bag. You can then get and set cats however you want in the public interface of your webservice, and eveything will work fine.
- Luke