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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T15:36:38+00:00 2026-06-12T15:36:38+00:00

I have two entities: Account { @Id Long id; } Preference { … @ManyToOne

  • 0

I have two entities:

Account {
  @Id
  Long id;
}

Preference {
  ...
  @ManyToOne
  private Account account;
}

When saving a Preference, I have the accountId, but I don’t have an Account entity. How should I save the preference in this situation?

Load the Account entity and set it on the preference? To me, that seems like an erroneous trip to the database.

Have an accountId field that is persistable and make the Account field read-only? Having both an accountId field and an Account field seems redundant?

Use a NamedQuery to persist the Preference? I was hoping to just generically save an entity without special logic for.

  • 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-06-12T15:36:39+00:00Added an answer on June 12, 2026 at 3:36 pm

    Use em.getReference(Account.class, accountId). It returns an uninitialized proxy on the entity, without going to the database. Your use-case is the main reason for the existence of this method.

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

Sidebar

Related Questions

I have two entities that usually have one-to-many relationship, but in rare cases should
I have two entities @Entity public class Tabulka{ @OneToMany(mappedBy = tabulka) private List<VysledkyHraca> vysledkyHraca;
I have two entities A and B. public class A{ @Id @GeneratedValue private Integer
A have two entities. For example timing settings and orders. @Entity public class TimingSettings{
I have two entities types: RunContainer parent entity type Run child entity type Run
I have two entities like the following: @Entity public class Trip { @OneToMany(mappedBy =
I have two entities, Account and Subscription with a many-to-many association between them. I
I have two entities referenced one to many. When entity framework created the table
I have two entities, Parent and Child, in Entity Framework. The parent has a
I have two entities: Event and Comment. @Entity @Table(name = events) public class Event

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.