Announcement Announcement Module
Collapse
No announcement yet.
Hibernate backed model object in non-db situation Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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.

    Comment

    Working...
    X