facebook

saveOrUpdate, error while inserting

  1. MyEclipse Archived
  2.  > 
  3. Database Tools (DB Explorer, Hibernate, etc.)
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #249672 Reply

    gummadi_b
    Member

    This is pretty basic stuff. All I am trying to do is insert a Customer.
    I am using mysql, tomcat, spring, struts, hibernate.
    Using myeclipse I reverseengineered all my tables which created hibernate mapping files, Hibernate Object and DAOs.

    When I use findById it works fine, but when I try to insert a customer it fails. Error I get is HibernateOptimisticLockingFailureException (Batch update returned unexpected row count from update: 0 actual row count: 0 exprected: 1″

    Customer.hbm.xml
    ————————
    has one id
    <id name=”customerId” type=”integer”>
    <column name=”CustomerId” />
    <generator class=”identity” />
    </id>

    properties

    <set name=”tktsOrders” inverse=”true”>
    <key>
    <column name=”CustomerId” not-null=”true” />
    </key>
    <one-to-many class=”com.dal.hibernate.dbo.Orders” />
    </set>

    I inserted all values into customer object expect for orders. Hope this information helps you guys to help me.
    Please advice me. What am I doing wrong?

    Thanks
    Tech Lover

    #249675 Reply

    Haris Peco
    Member

    Tech,

    Please, send us table ddl (create table) and code for saveOrUpdate. if it possible
    What is your version eclipse and myeclipse and do you use hibernate libraries from MyEclipse ?

    Best regards

    #249677 Reply

    gummadi_b
    Member

    Yup, I am using hibernate libraries from MyEclipse. Eclipse version is 3.1 and the myeclipse version is 4.1.1.
    After troubleshooting for couple of hours I found out that, BeanUtils is the culprit. I used BeanUtils.copyProperties, because of which my Id field is assigned a default value of 0(zero).

    I guess hibernate creates an update statement as opposed to insert statement because id field has a value.
    I had to modify the hbm file and declare unsaved-value=”0″. Now it works fine.

    Is this the right way of doing it or if not can you please point me to the best practice of achieving this?

    Thanks

    #249683 Reply

    Haris Peco
    Member

    Tech,

    If it work then it is correct.

    Best

Viewing 4 posts - 1 through 4 (of 4 total)
Reply To: saveOrUpdate, error while inserting

You must be logged in to post in the forum log in