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

The Archive Base Latest Questions

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

I would like some advice on how to best layout my JPA entity classes.

  • 0

I would like some advice on how to best layout my JPA entity classes. Suppose I have 2 tables I would like to model as entities, user and role.

Create Table users(user_id primary key,
                   role_id integer not null )
Create table role(role_id primary key,
                  description text,
                  )

I create the following two JPA Entities:

@Entity
@Table(name="users")
@Access(AccessType.PROPERTY)
public class User implements Serializable {
      private Long userId;
      private Long roleId;
      private Role role;

      @Column(name = "user_id")
      @Id
      public Long getUserId() {}

     @Column(name = "role_id")
      public Long getRoleId() {}

      @ManyToOne()
      JoinColumn(name="role_id")
      public Role getRole() {}
}

Role Entity:

@Entity
@Table(name="Role")
@Access(AccessType.PROPERTY)
public class Role implements Serializable {
      private String description;
      private Long roleId;


      @Column(name = "role_id")
      @Id
      public Long getRoleId() {}

     @Column(name = "description")
      public Long getDescrition(){}

      @ManyToOne()
      @JoinColumn(name="role_id")
      public Role getRole() {}
}

Would the correct way to model this relationship be as above, or would I drop the private Long roleId; in Users? Any advice welcomed.
When I map it this way, I receive the following error:

 org.hibernate.MappingException: Repeated column in mapping for entity:
  • 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:25:52+00:00Added an answer on May 28, 2026 at 5:25 am

    Yes, you would drop the private Long roleId mapping when you have a @ManyToOne on the same column.

    As the error implies, you can only map each column in an @Entity once. Since role_id is the @JoinColumn for the @ManyToOne reference, you cannot also map it as a property.

    You can, however, add a convenience method to return the role ID, like

     public Long getRoleId() {
       return role.getId();
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like some advice on the best approach to use in the following
I would like some advice on the best approach for transferring DB data from
I'm would like some advice on the best data persistence solution to use for
I am designing RESTful Api's and would like some advice on designing an API
I am considering starting an OSS project and would like some advice. I would
I'm looking into building a distributed application and would like some advice on the
I would like some of my preferences to have icons, like the Settings app.
I would like to get some advice on structuring my javascript code and jquery
I just started with WPF and would like some advice with the following: I
Hey all, I would like some advice from the programming community. I am building

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.