I want to check existance of object in database without knowing his id. I'm using a HQL query for it, but i'm recieving an excenption
org.hibernate.TransientObjectException:
object references an unsaved transient instance - save the transient instance before flushing
Here is my code exapmle:
ObjectToCheck obj = new ObjectToCheck(); //this is a mapped entity
obj.setName("name");
obj.setValue("value");
List list = session.createQuery("from ObjectToCheck as o where o = ?")
.setEntity(0, obj)
.list();
I understand the reason of this exception, but how can i make query with transistent object as a parameter? I want to know, is the equal object in database or not.