tangara goh wrote:
Deyan Perov wrote:
Cascades bubble "down".
Sorry, I don't get this.
In your example, any of the listed operations performed on Town will also be performed on all of the Students stored in the list.
Does this mean because I wrote this - @OneToMany(mappedBy = "townEntity"...) or because it this annotation is in TownEntity class?
Did you persist the Student before persisting the Town? Because otherwise the Student shouldn't have been persisted.
This is how I persist the Student.
Be aware with REMOVE. Only use it if your entities are really tied together. If a Student can live without a Town, removing the Town should usually leave the Student intact. If you use REMOVE (or ALL) on every relationship, you can end up removing many records by just removing one. You'd need to first break the relationship (by removing the link between the two) before removing to prevent this.
Thank you for suggestion.
In my case I should left these:
But what about the other side, above attribute TownEntity? I don't see any affect do I left CascadeType.ALL or put only any other cascade. I know if I don't have any cascade it will be CascadeType.ALL by default.
Campbell Ritchie wrote:Is it this method, Rob?
Rob Spoor wrote:. . . new toArray method: . . .
Deyan Perov wrote:When I remove PERSIST it still creates the Town or Student, only where I saw affect is when I put CascadeType.REMOVE. If I remove a Student it will remove his Town too. Then I created two students and one town and when I remove the student id = 1 it removed both students and town.
Dave Tolls wrote:
Jesse Silverman wrote:
I memorized today that the preferred way to get a cloned array out of a list is:
Not sure that's necessarily the preferred way.
toArray() uses the supplied array if it's long enough to fit the contents of the list, otherwise it creates a new one of the correct size.
So with the above it will essentially create an additional object to then fill whereas:
will use the supplied array.
I mean, there's not exactly much in it, but one creates an object that's not used for anything other than figuring what type to return, and the other just uses the given object.