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

  • Home
  • SEARCH
  • 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 7579259
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T17:37:59+00:00 2026-05-30T17:37:59+00:00

I have a Client object that owns a number of Address objects. So, my

  • 0

I have a Client object that “owns” a number of Address objects. So, my Client class defines a set to hold the address objects as follows :

@OneToMany(fetch=FetchType.LAZY, mappedBy="client", cascade={CascadeType.ALL})

and my Address class defines a Client instance variable like this :

@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(name="ClientId", nullable=false)

I have a form that allows the user to enter Client details and Address details at the same time, with the intention being that saving the form will cause the Client to be saved to the database, and the Cascade will cause the address to also be saved.

I can get this to work, but only if I manually set the Client property on the Address object in the controller immediately before I save the client object.

    public String clientSave(@ModelAttribute("form") AddClientForm form, ModelMap model) {
    logger.debug("clientsave");
    Client client = form.getClient();

    HashSet<Address> addresses = new HashSet<Address>(form.getAddresses());

    // TODO - Should I have to do this?
    for (Address a : addresses){
        a.setClient(client);
    }

    client.setAddresses(addresses);

    clientService.saveClient(client);

Should I need to do this, or am I missing something ?

  • 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-30T17:38:01+00:00Added an answer on May 30, 2026 at 5:38 pm

    Yes, you need to do this. Hibernate looks at the owner side of the association to persist it, and the owner side is the side which doesn’t have the mappedBy attribute.

    In general, you are responsible of the coherence of the object graph. It’s thus often a good idea to have a method addAddress() in Customer which sets both sides of the association. Your setAddresses() method could do that as well.

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

Sidebar

Related Questions

I know that the asp.net repeater doesnt have a Client side object model, and
I have an object that was previously round-tripping from the server to the client
I am using Distributed Objects (DO) in Objective-C. I have a server object that
Say I have a object Client that has a child StatusType object. Both implement
I have a C# client and a java server. I have data object that
I have an object that contains public class PositionsChannelApplicationGroups { public PositionsChannelApplicationGroups(){} private Map<MyObj1,
This is an odd problem. I have a client object that I am building
I have an object with the following structure: (pseudocode) class Client { - int
I have an object (Client * client) which starts multiple threads to handle various
I have my domain object, Client , I've got a form on my JSP

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.