Announcement Announcement Module
Collapse
No announcement yet.
hiberante Many-to-Many: save the relationship in one 'save' ? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • hiberante Many-to-Many: save the relationship in one 'save' ?

    In hiberante Many-to-Many, is it possible like this
    Code:
       Teacher t = new Teacher();
       List<Student> s = new ArrayList<Student>();
       // add some students to the List
       t.setStudents(s);
       getHibernateTemplate().save(t);
    In the last step save, it will save object Teacher and each of Students ?

    Usually, we need firstly create student and save it, create Teacher and save it. Then set the array to Teacher and update it. It is too many steps. So I am curious if we have some shortcut ?

    Thanks.

  • #2
    Yes, look for "cascade" in the Hibernate documentation. But also read about the possible consequences.

    Joerg

    Comment


    • #3
      Originally posted by Jörg Heinicke View Post
      Yes, look for "cascade" in the Hibernate documentation. But also read about the possible consequences.

      Joerg
      could you please tell me "the possible consequences" ? Or give me a link.

      Thanks.

      Comment


      • #4
        Originally posted by czy11421 View Post
        could you please tell me "the possible consequences"?
        Hmm, nothing in particular. But it might be easy to lose track of what's saved and loaded with cascade. It might slow down the application at the end. The chapter 21 in the Hibernate reference is just about such an example.

        Joerg

        Comment

        Working...
        X