Announcement Announcement Module
Collapse
No announcement yet.
Reload one-to-many relationship Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Reload one-to-many relationship

    Hi,
    We are using JSF (Java Server Faces), Spring and Hibernate to realize a project. Our problem is reloading a one-to-many lazy relationship, problem is:

    We have a class A which has two relationships with class B and C. It has one-to-many non-lazy relationship with class B and one-to-many lazy relationship with class C.
    Our DAO classes extend HibernateDAOSupport and we use TransactionProxyFactoryBean to manage transaction demarcation in service layer. We retrieve class A with relations in a view without initializing lazy connection. In another view we initialize lazy connection with
    Code:
    session.lock(a,LockMode.NONE)
    a.getCs().size();
    return a;
    (we don't know this is a correct pattern or not? We tried OpenSessionInView pattern we didn't see any advantage of it, TransactionProxyFactoryBean does same thing (we guess!))
    and we access class C with no errors.
    On the other hand another program adds new rows to the table C. When user wants to get new data from table C with the same method
    Code:
    session.lock(a,LockMode.NONE)
    a.getCs().size();
    return a;
    we access same class C with no new data.

    The questions are:

    Do we need to do extra things to refresh the one-to-many relationship? Or we need to retrieve the class A with all relationships every time (we dont want this because A->B relationship doesn't need to be refreshed)?

  • #2
    I wouldn't worry about manipulating hibernate directly.

    If your DAO extends HibernateDAOSupport, and you are getting your objects from the Hibernate Session then your objects will already be attached to the hibernate session. Traversing the object model will do "the right thing" because they are attached to the hibernate session.

    When it comes to hibernate; the less code you right the better it works

    Comment


    • #3
      You don't need refreshing as long as your objects are attached to the hibernate session - you have to worry about refreshing when your objects are disconnected (and in this case it's easy solvable by attaching them to a session).

      Comment

      Working...
      X