I have a problem when trying to save an inherited object using TemplateHibernate:
Let’s say that I have two classes as following:
Contact <——— EntrepriseContact
and here is the contact.hbm.xml
<joined-subclass name="Entreprise" table="Entreprise">
<key column="ID_ENTREPRISE" />
<property name="numSiret">
<column name="NUM_SIRET" />
</property>
</joined-subclass>
When I create a Entreprise object and save it using Hibernate, it works
try
{
SessionFactory sessionFactory =
new Configuration().configure().buildSessionFactory();
session = sessionFactory.openSession();
org.hibernate.Transaction tx = session.beginTransaction();
........................................
session.saveOrUpdate(entreprise);
tx.commit();
}catch(Exception e){
System.out.println(e.getMessage());
}
But when I tried to use HibernateTemplate, I got the following error:
org.springframework.dao.InvalidDataAccessApiUsageException: object references an unsaved transient instance - save the transient instance before flushing: domain.Contact; nested exception is org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: domain.Contact
How can I fix this problem?
Note that when I tried with Contact, I worked in both situations, but with Entreprise, it didn’t work 🙁
Check out Spring Source Documentation, to check how to use hibernateTemplate.