Results 1 to 2 of 2

Thread: Hibernate backed model object in non-db situation

  1. #1

    Default Hibernate backed model object in non-db situation

    I need a little advice.

    We've got a Spring managed, hibernate-backed domain/model object that looks like this:

    Address
    - String firstname
    - String lastname
    - String street1
    - State state
    - Country country

    Both State and Country are objects that, via hibernate, are many-to-one relationships to records in the state and countries table.

    My question is this:

    Can I use this object without using hibernate? In other words, the object is everything I want it to be with regard to fields, getters, setters, etc.

    But I want to create this object, store data in it, and later throw it away without it ever getting persisted to the database. Any danger there? Will anything complain?

    How do I handle the State and Country objects? When I create the object I need to set State and Country based on the StateID and CountryID which I have. But without hibernate in the picture the system won't know how to create a State object or a Country object, right?

    Any guidance is most appreciated.

    Thanks,

    - Gary

  2. #2
    Join Date
    Jan 2005
    Location
    Bucharest, Romania
    Posts
    5,403

    Default

    You can use your object without a problem - HB doesn't change Java semantics. As long as your object is not binded/attached to a HB Session, you can do whatever you want to it and the changes will not be propagated.
    However, if your object is attached to a session you can make the session read-only (FlushMode.NEVER) but be careful because usually you will run into problems in the long term managing readOnly session and read/write ones.
    How do I handle the State and Country objects? When I create the object I need to set State and Country based on the StateID and CountryID which I have. But without hibernate in the picture the system won't know how to create a State object or a Country object, right?
    It depends on the workflow of your application - if you use the ID inside the equals/hashcode of your objects then you need to set them manually. One solution would be to use a business key (based on other properties which will be set anyways) or use a UUID which can be created automatically when the object is instantiated.
    Costin Leau
    SpringSource - http://www.SpringSource.com- Spring Training, Consulting, and Support - "From the Source"
    http://twitter.com/costinl
    Please use [ c o d e ] [ / c o d e ] tags

Similar Threads

  1. Domain Object Model and Hibernate detached object
    By yfmoan in forum Architecture
    Replies: 11
    Last Post: Oct 14th, 2005, 11:05 PM
  2. Replies: 2
    Last Post: Oct 10th, 2005, 05:12 PM
  3. Form model and hibernate object id
    By riankruger in forum Data
    Replies: 1
    Last Post: Sep 15th, 2005, 02:21 AM
  4. Loosing my SecureContext
    By sklakken in forum Security
    Replies: 3
    Last Post: Jul 21st, 2005, 01:44 PM
  5. Content Provider vs View Model
    By Martin Kersten in forum Swing
    Replies: 21
    Last Post: Mar 10th, 2005, 02:25 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
  •