Results 1 to 3 of 3

Thread: Update single table in Hibernate

Hybrid View

  1. #1
    Join Date
    Jun 2007
    Posts
    1

    Default Update single table in Hibernate

    I'm a newbie.

    i have the following tables:
    Person
    person_oid (PK)
    height
    weight
    country_oid (FK)
    ...

    Country
    country_oid (PK)
    country_name
    ...

    so I have the following object:
    Person
    personOid
    height
    weight
    Country

    if I only want to update height and weight, I still have to retrieve Country object and set to Person object, then call saveOrUpdate(person). Is there anyway I can update the Person object without issue a sql to get the Country object?

    Thanks in advance!

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,632

    Default

    Why would you need to have the country? Make sure that your mappings are correct and make lazy what can be lazy. Hibernate is smart enough to now if it needs to update a country then.

    Also before updating an instance you probably retrieve it from the database, update its properties, and store it. If you do it that way, you don't have the problems you mentioned.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    You probably don't even need to save the item, all you need to do is retrieve it and change the values.
    http://www.hibernate.org/hib_docs/v3...ate-transitive
    Last edited by karldmoore; Aug 29th, 2007 at 12:09 PM.
    Barracuda Networks SSL VPN Lead Developer
    http://pramatr.wordpress.com
    http://twitter.com/karldmoore
    http://www.linkedin.com/in/karldmoore
    Any postings are my own opinion, and should not be attributed to my employer or clients.

Posting Permissions

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