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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T04:57:41+00:00 2026-05-20T04:57:41+00:00

I have a User class that has @Embedded a class Profile. How can I

  • 0

I have a User class that has @Embedded a class Profile. How can I give the instances of Profile a reference to their owner the User class?

@Entity
class User implements Serializable  {
   @Id @GeneratedValue(strategy = GenerationType.IDENTITY)
   private Integer id;

   @Embedded Profile profile;

   // .. other properties ..
}

@Embeddable
class Profile implements Serializable {

   User user; // how to make this work?

   setURL(String url) {
      if (user.active() ) { // for this kind of usage
         // do something
      }
   }

   // .. other properties ..
}
  • 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-20T04:57:42+00:00Added an answer on May 20, 2026 at 4:57 am

    Assuming JPA rather than strictly Hibernate, you might do this by applying @Embedded to a getter/setter pair rather than to the private member itself.

    @Entity
    class User implements Serializable {
       @Id @GeneratedValue(strategy = GenerationType.IDENTITY)
       private Integer id;
    
       @Access(AccessType.PROPERTY)
       @Embedded
       private Profile profile;
    
       public Profile getProfile() {
          return profile;
       }
    
       public void setProfile(Profile profile) {
          this.profile = profile;
          this.profile.setUser(this);
       }
    
       // ...
    }
    

    However, I would question whether an embedded entity is what you want at all in this case, as opposed to a @OneToOne relationship or simply “flattening” the Profile class into User. The main rationale for @Embeddable is code reuse, which seems unlikely in this scenario.

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

Sidebar

Related Questions

I have a class Bar that has a user-defined list of config keys and
I have implemented a LoginAccess class that prompts the user to enter their active
I have an app that has settings the user can pick before running the
I have a User entity which has a HasCompletedSecurity property which indicates whether that
Here is my current situation: I have a user class that has an attribute
I have a User entity that has a Current Location field (city and country).
I have a User class that has many posts and the post class has
I have a User class that has a property called Creator which is of
I have a User class that has a UserProfile class. The email is stored
I have a user-defined class MyClass that has a __hash__ and __eq__ implementation that

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.