Hi, all.
We are using Hibernate 3.3.2. For various reasons, we're transitioning to application-assigned id's in our app. We use Hibernate as the JPA provider, marking our entities with JPA annotations. What we are seeing with application assigned id's is not matching with the documentation. We actually like what Hibernate appears to be doing rather than what the documentation says will happen, but we're confused as to why things are working as we want rather than as the documentation states. :) Specifically:
http://www.hibernate.org/hib_docs/refer ... d-assigned states "Choosing the assigned generator makes Hibernate use unsaved-value="undefined", forcing Hibernate to go to the database to determine if an instance is transient or detached, unless there is a version or timestamp property, or you define Interceptor.isUnsaved()." We have not explicitly chosen "assigned" for the id generator, but my understanding is that by having the entity's member variable marked as @Id, but no @GeneratedValue annotation is how you specify application assigned id's in JPA. This is what we've done (and we are assigning our identifiers and they are being used), but we (to our surprise, but thankfulness) find that no queries are being done to figure out if it's new or not when we hand new entities to the persist() method and then flush() the EntityManager (we have not implemented any kind of interceptor, marked anything as an unsaved-value of any kind, or have any attributes marked as @Version).
- and -
http://www.hibernate.org/hib_docs/entit ... ml#d0e1000 states "Exception: entity instances using application-assigned identifiers are inserted when they are saved." However, when we call EntityManager.persist() on our entities, it does not issue the SQL at that point, but waits until one of the other times a flush() occurs. I know EntityManager.persist() is probably not identical to Session.save(), so that might be the reason?
While what we're seeing is what we
want to happen, it's not what the documentation appears to say will happen. We'd like to know if what we're seeing is expected behavior and we can rely on things working this way, or if things are behaving this way by happenstance and we shouldn't rely on this behavior continuing in future releases.
Thanks in advance,
Greg