Announcement Announcement Module
No announcement yet.
saveOrUpdate fails on insert Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • saveOrUpdate fails on insert

    On a table where the pk is oracle sequence using saveOrUpdate works for either inserts or updates. But on tables where the pk is anything else, typically a fk to another table when calling saveOrUpdate a insert fails, no error message just no row added. If I change the method to just save then the insert is successful. Any suggestions? thanks


    <property name="hibernateProperties">
    <prop key="hibernate.dialect">
    <prop key="hibernate.connection.autocommit">false</prop>
    <prop key="show_sql">true</prop>
    <!-- Transaction manager for a single Hibernate SessionFactory (alternative to JTA) -->
    <bean id="transactionManager"
    class="org.springframework.orm.hibernate.Hibernate TransactionManager">
    <property name="sessionFactory">
    <ref local="sessionFactory"/>

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
    <class name="com.model.Working" table="poc_working">

    <id name="progSolNumber" type="string" column="prog_sol_number">
    <generator class="assigned" />

    <!-- <property name="progSolNumber" column="prog_sol_number" not-null="true"/>

    <property name="accountNumber" column="account_number" not-null="true"/>
    <property name="status" column="status" not-null="false"/>
    <property name="batchId" column="batchId" not-null="true"/>

  • #2
    Check out the Hibernate FAQ.

    It could be this problem: saveOrUpdate(), or cascade save, executes UPDATE instead of INSERT!


    • #3

      Due to its inherent nature, entities that use this generator cannot be saved via the Session's saveOrUpdate() method. Instead you have to explicitly specify to Hibernate if the object should be saved or updated by calling either the save() or update() method of the Session.