java - 如何在Spring中使用Template Hibernate保存继承的类

标签 java hibernate spring

尝试使用 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/

相关文章:

java - 由 : org. apache.axis2.AxisFault 引起:无法接合模块:rampart

java - 4 小时后不应访问 Otp

java - 如何使用 java 11 运行 scala repl?

java - HQL : Help in preforming join

java - 如何通过客户端域网络保护我的源代码

java - 并发标记和清除算法详细信息

java - LiquiBase diff 和 diffChangeLog 未检测到更改

regex - 如何在JPQL中应用正则表达式?

java - Spring 是否支持 SharePoint

java - org.springframework.beans.factory.BeanCreationException :