尝试使用 TemplateHibernate 保存继承的对象时遇到问题: 假设我有以下两个类(class): 联系方式 <--------- 企业联系方式 这是 contact.hbm.xml
<joined-subclass name="Entreprise" table="Entreprise">
<key column="ID_ENTREPRISE" />
<property name="numSiret">
<column name="NUM_SIRET" />
</property>
</joined-subclass>
当我创建一个 Entreprise 对象并使用 Hibernate 保存它时,它可以工作
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());
}
但是当我尝试使用 HibernateTemplate 时,出现以下错误:
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
如何解决这个问题?
请注意,当我尝试使用 Contact 时,我在两种情况下都可以工作,但使用 Entreprise 时,它不起作用:(
最佳答案
查看Spring Source Documentation ,查看如何使用 hibernateTemplate。
关于java - 如何在Spring中使用Template Hibernate保存继承的类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8706894/