I am new to Hibernate and am trying to figure out how to let Hibernate figure out whether an INSERT or UPDATE is appropriate, based on whether or not the object already exists in the underlying DB.

I was hoping to see a Session#createOrUpdate(...) method (or something similar) but don't see any (although I do see an interesting method called persist(...).

So I ask: how can I tell Hibernate "hey, here's a User object; if it doesn't exist then INSERT it, and if it does exist, then UPDATE it"? Thanks in advance!

有帮助吗?

解决方案

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top