I am getting the following error when trying to execute an HQL query:
Caused by: org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing:
The object it is complaining about is a new object that I created. But that new object has no impact on the results of my query. The model object is only very loosely related to any object selected by my query. I do not understand why Hibernate is throwing an exception.
I have worked around this in the past by keeping new objects hidden from Hibernate until after I run my queries. If I create the model objects but don’t associate them to other existing objects, then Hibernate does not know they exist yet. I create the associations right before I am ready to save the new data. I cannot do that in this case. There has to be a better way to do this.
Why does Hibernate think that my new data will have an impact on the results of the query? Is it because of the way I set up my relationships? Almost all of my relationships in my database are defined in Hibernate, which means that nearly every object could be linked to any other object in some way.