Results 1 to 7 of 7

Thread: saving data via hibernate

  1. #1
    Join Date
    Sep 2004
    Location
    Vienna, Austria
    Posts
    8

    Default saving data via hibernate

    hello everybody

    we are using struts, spring and hibernate although there are some problems occuring, specially one when i try to save in a struts action -
    this is just a testcase but i want to load data and save the modified data again in one action - as i said just a test.

    after removing all errors the actions seems to be doing what i want - except hibernate does not save the object.
    my structure is the following:

    group table - text table
    from group to text there is a ony-to-many relation
    when i get back the set i want to modify an item in the related text object and save the group item.
    after saving i get back the correct item with the modified value but in the database the old value remains.
    do i have to commit or something like that?
    i think spring handles session and transactions by it own, doesn't it?

    maybe somebody could help me in this case -
    thanx in advance

    greetinx

    tuor

  2. #2
    Join Date
    Aug 2004
    Location
    San Mateo, CA
    Posts
    1,265

    Default

    i think spring handles session and transactions by it own, doesn't it?
    You need to configure declarative transaction management, using TransactionProxyFactoryBean or the like. Please see examples such as the PetClinic and PetStore.

    Your Struts action is presumably not in a transaction scope. In general you should have transaction boundaries around business objects, and they shouldn't span into the web tier.
    Rod Johnson - GM, SpringSource Division, VMware
    http://www.springsource.com
    Spring From the Source

  3. #3

    Default

    That is similar problem I'm having too. I'm using TransactionManger. I'm deleting the existing records, from the "Groups" table which is many-to-one to the "Users" table, before I add the new modified data record to the Groups table again.

    After save, it returns the object with the correct modified values, but the database still has the old values

  4. #4

    Default

    Correction to my last post...

    After save, it returns the object with the correct modified values.
    However, when I look in the database, the records were deleted but the new records were never added.

  5. #5
    Join Date
    Aug 2004
    Location
    Sydney, Australia
    Posts
    2,768

    Default

    Check your cascade="" setting of the parent object in the .hbm.xml file. If you don't want to specifically saveOrUpdate for each child object, the parent will need a cascade setting like "all-delete-orphan". There are half a dozen cascade settings to fine-tune the exact desired persistence by reachability - check the Hibernate documentation.

  6. #6

    Default

    Now that I can add, update and delete a record in the User table but I cannot add or update to the collection that is related to that user record.

    When I delete a user all the roles related to that user get deleted too (which is what I expected it to do).

    Yet, why can I not add or update the collection (roles) of a user?

    The relationship of User to Role table is one-to-many and is set to lazy=true.

    Can someone help? I just want to be able to add a new user and update an existing user such that the roles will get added or updated too.

    Thank you

  7. #7
    Join Date
    Aug 2004
    Location
    Toronto, Canada
    Posts
    736

    Default

    You may well get an answer here, but at this point you'll have a better chance of getting a reply if you go to the Hibernate forums, since this is pretty much a Hibernate usage issue as far as I can tell.

    Regards,
    Colin Sampaleanu
    SpringSource - http://www.springsource.com

Similar Threads

  1. Replies: 7
    Last Post: Apr 18th, 2007, 09:50 AM
  2. UpgradeAcegi Security System from 0.6.1 to 0.8.3
    By mannobug in forum Security
    Replies: 3
    Last Post: Sep 23rd, 2005, 07:00 PM
  3. Loosing my SecureContext
    By sklakken in forum Security
    Replies: 3
    Last Post: Jul 21st, 2005, 01:44 PM
  4. Multiple Data Sources + Hibernate + Spring
    By joeserel in forum Data
    Replies: 2
    Last Post: May 18th, 2005, 09:22 AM
  5. Replies: 3
    Last Post: Nov 19th, 2004, 07:16 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •