Announcement Announcement Module
Collapse
No announcement yet.
saveOrUpdate fails on insert Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • 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

    Scott


    <property name="hibernateProperties">
    <props>
    <prop key="hibernate.dialect">
    net.sf.hibernate.dialect.Oracle9Dialect</prop>
    <prop key="hibernate.connection.autocommit">false</prop>
    <prop key="show_sql">true</prop>
    </props>
    </property>
    </bean>
    <!-- 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"/>
    </property>
    </bean>



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


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

    <!-- <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"/>
    </class>
    </hibernate-mapping>

  • #2
    Check out the Hibernate FAQ.

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

    Comment


    • #3
      nevermind

      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.

      Comment

      Working...
      X