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 6611131
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:55:50+00:00 2026-05-25T19:55:50+00:00

I have 2 entities Customer and address please find the code below, I have

  • 0

I have 2 entities Customer and address please find the code below, I have omitted boiler plate code for simplicity.

public class Customer  implements java.io.Serializable {
  private static final long serialVersionUID = 3116894694769321104L;
     private short customerId;
     private Address address;
     private String firstName;
     private String lastName;
     private String email;
     private boolean active;
     private Date createDate;
     private Date lastUpdate;


    // Property accessors
    @Id
    @Column(name="customer_id", unique=true, nullable=false, insertable=true, updatable=true)

    public short getCustomerId() {
        return this.customerId;
    }

    public void setCustomerId(short customerId) {
        this.customerId = customerId;
    }
    @ManyToOne(cascade={CascadeType.ALL},
        fetch=FetchType.LAZY)

        @JoinColumn(name="address_id", unique=false, nullable=false, insertable=true, updatable=true)

    public Address getAddress() {
        return this.address;
    }

    public void setAddress(Address address) {
        this.address = address;
    }

and Address class is :

public class Address  implements java.io.Serializable {


    // Fields    

     private short addressId;
     private short customerId;
     private String address;
     private String address2;
     private String district;
     private String postalCode;
     private String phone;
     private Date lastUpdate;
     private Set<Customer> customers_1 = new HashSet<Customer>(0);


    // Constructors

    /** default constructor */
    public Address() {
    }

   // Property accessors
    @Id
    @Column(name="address_id", unique=true, nullable=false, insertable=true, updatable=true)

    public short getAddressId() {
        return this.addressId;
    }

    public void setAddressId(short addressId) {
        this.addressId = addressId;
    }

    /**
     * ??????what goes here
     */
    public short getCustomerId() {
        return customerId;
    }

    /**
     * @param customerId the customerId to set
     */
    public void setCustomerId(short customerId) {
        this.customerId = customerId;
    }

I need to persist the customer id as a foreign key in address table.

  • 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-25T19:55:51+00:00Added an answer on May 25, 2026 at 7:55 pm

    Just use @ManyToOne relationship with Customer. So, instead of customerId in Java code you will be operates with Customer object, but at database level Hibernate will use foreign key to table with customer.

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

Sidebar

Related Questions

I have a 3-leveled hierarchy of entities: Customer-Order-Line, which I would like to retrieve
I have two tables Group and Customer and of course two entities Group and
I have two entities, Customer and Order, both of which I have created types
When I have entities in my domain with lists of things, should they be
Say I have entities organized in a hierarchy with Parent being the root entity
Should entities have behavior? or not? Why or why not? If not, does that
I have two entities Foo and Bar with a Many to Many relationship between
I have two entities, each from a different database and therefore different edmx files.
I have two entities, Entity1 and Entity2, on a one to many relationship. On
I have a situation where I have two entities that share a primary key

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.