Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7073373
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:55:18+00:00 2026-05-28T05:55:18+00:00

I have three classes (House, Room, Address) which are persistent (Mapped with JPA/Hibernate) @Entity

  • 0

I have three classes (House, Room, Address) which are persistent (Mapped with JPA/Hibernate)

@Entity
@Table(name = "HOUSE")    
@AttributeOverrides({@AttributeOverride(name = "house_id", column = @Column(name =     "house_id"))})
  public class House{


     @Basic     
     private String key;
     @OneToMany(mappedBy = "house", cascade = {CascadeType.ALL},    orphanRemoval = true)
     private List<Room> rooms;

        @OneToOne(fetch = FetchType.LAZY, cascade = {CascadeType.PERSIST})
        @JoinColumn(name = "add_id")
        private Address address;
}

 public static void main(String args){
 String key="key1";
 Room room1=...
 Room room2=...
 List<Room> rooms=//add the two rooms
 .
 .
 House house= new House(key, rooms, address);

 // Here is my question.
 // Now I call the save method on the persistent class

  house.save();
}

1) Are Address and Room objects going to be persisted automatically or should I have to call save method on each of them (room1.save(), room2.save(), address.save()) before calling house.save()? How about when I delete the house obj?

2) The class “house” is the top of the hierarchy. I understood that if we call the save on the owning entity, it will persist the room and address as well. How about the reverse? If I edited the room, how do I make sure that the “house” knows about it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T05:55:19+00:00Added an answer on May 28, 2026 at 5:55 am

    not the way you have it set up. you need to mark one of your members in each entity as id with annotation @Id. Then you need to map how your composed entities relate to each other. This is done with different annotations, such as @OneToMany and @ManyToOne.

    Finally, if you want to be able to persist composed entities by just calling hibernateSession.save with the owning entity in the relationship, all those entities it owns must be marked with cascade save, so that the persisting is cascaded down the ownership tree.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have three classes mapped using the table-per-subclass class mapping strategy. The tables are:
I have three classes which implement the same protocol, and have the same parent
i have three classes. 1.Class:` public class Handler { private String name; private String
I have three classes which I have a problem with. They are named: GameScene,
I have three classes, one main class, one GUI class which uses awt+swing to
I have three classes a) Parent - Which contains some properties, an Item collection
I have three classes: a TopClass which contains an instance of a BottomClass pointer.
I have three classes: Base, Derived (inherits from Base), and Stats (which uses a
I have three classes: A data holder class CDataHolder, which uses a Pimpl pattern
I have three classes which all make different works but I need to run

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.