Hi folks,
I have a simple entity relationship where a Person can have many Photo. The Person entity has a List<Photo>, and Photo has a Person class member.
At the moment things work just fine as long as I do the following:
Person.getPhotos().add(Photo);
Photo.setPerson(Person);
Do I always have to do it from both sides manually? Is there any way I can get this done automatically?
My somewhat-hairy idea (I'm new to Java) was to extend ArrayList<> and create my own class that raises an event when items get added or removed. That didn't work since Hibernate didn't seem to know anything about my custom generic collection. The error was something like "expecting someSupaDupaList, actual was PersistentBag"...Things just got more and more complicated from there on, which made me think there must be an easier way of doing this.
Has anybody encountered this kind of situation before? And what did you implement to handle this?
Any hints/suggestions would be greatly appreciated.
Many thanks,
D.
UPDATE:
Nevermind - I can't believe how complicated I made the issue. Found the solution in
http://forum.hibernate.org/viewtopic.php?t=965856 - incredibly simple!