|
Your compareTo method can return any negative or positive integer to show smaller-than or larger-than, so you can remove the ternary operator. "return c;" will do the job more efficiently, and it's easier to read.
You'll have to define a hashCode and equals method, as that's almost certainly what's causing the oddness. If photos can never have their name changed, then it'll be easy (name is the business key), otherwise you're in a pickle, because there's no business key in the class. You could switch to using an assigned key and use the database key as the business key, but you can't do that with your current mapping, because the id changes when you save a photo for the first time.
Also note that many-to-many mappings don't support cascade delete-orphan. You should either use a one-to-many mapping, or else change your cascade to just "all".
|