Hibernate Fun
Nov. 16th, 2008 05:02 pm![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
I am struggling through Hibernate funness. I bought the O'Reilly book, but it's a bit thin, and after reading a few peoples' reviews, I also got the Persistence with Hibernate book from Manning which is AWESOME.
the merge method is evil. It looks like a good replacement for persist() but it isn't. merge() doesn't actually tie the object to the database state, so if you call merge() repeatedly on an object with no Id, it will save it repeatedly. persist() however does the right thing. The only thing merge gives you is the ability to save an object across sessions, but it would probably be better to attempt to re-attach the object instead of merging it.
the merge method is evil. It looks like a good replacement for persist() but it isn't. merge() doesn't actually tie the object to the database state, so if you call merge() repeatedly on an object with no Id, it will save it repeatedly. persist() however does the right thing. The only thing merge gives you is the ability to save an object across sessions, but it would probably be better to attempt to re-attach the object instead of merging it.