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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T07:02:28+00:00 2026-06-01T07:02:28+00:00

I have a simple question regarding accessing member variables of a model object. I

  • 0

I have a simple question regarding accessing member variables of a model object.

I have the following model objects:

@Entity
public class Person extends Model{
    @Id 
    public Long id;
    public String name;
}

@Entity
public class Account extends Model{
    @Id
    public String email;
    public String password;
    @OneToOne
    public Person person;
}

So far so good, Any given person can have a single account. The Account object is copied from the zentask example. After authentication I redirect to the index page which displays the user realname as stated in the Person.name member variable. The Account object is inserted in the page just as with the zentasks example like so:

Account.find.byId(Controller.request().username());

Now the following strange things happen in the template which i do not understand:

@account.person.name

results in a Null value inserted in the template while calling:

@account.person.getName()  or   @account.person.getName

results as expected with the correct name inserted from the person object.

@account.person

shows the .toString() of the person object, also correctly showing the name.

So to summarize: What is wrong with the code above? Why can I call the account.person value without any problems, but when I call account.person.name this does not work anymore

Thank you in advance!

Richard

  • 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-01T07:02:30+00:00Added an answer on June 1, 2026 at 7:02 am

    This is because JPA uses Aspects to intercept getter usage and fill-in the missing data from objects that are lazy-loaded. I don’t know what conventional thinking is, but I would not use public members ever with JPA for this reason, it will break the framework consistently.

    If you really want to use public members, you’ll have to mark relationships as eager fetching:

    @OneToMany(fetch=FetchType.EAGER)
    

    or explicitly fetch all of the object tree you’ll need in your template (ugh).

    In your case, the relationship, a OneToOne is defined on the other side of the relationship, if you define it on the Account side, it should fetch eager by default. I forget if you can define OneToOne on both entities, I think you can, but you might have to fiddle with it a bit.

    Overall, don’t use public members with JPA, it will break. Better yet, ditch JPA and use Anorm instead, it maps to the problem domain much more successfully than JPA. Issues like this consistently cause JPA implementations to take up twice as much implementation time as anyone seems able to predict.

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

Sidebar

Related Questions

I have a question regarding the Java Memory Model. Here is a simple class
I have simple type Question : public class Question { public string[] Tags {
I have a simple question regarding Entity declaration in JPA. I have an entity
simple question regarding HQL(Hibernate query language) so i have user class , that can
I have a simple question regarding jQuery selectors. I'm using the tablesorter and I
I have a simple, general question regarding a real small issue that bothers me:
Greetings all... I have a simple, yet annoying question regarding Spring Web MVC. I
I have a question regarding Antlr, I am building a simple parser with it
I have a simple question regarding the Minimax algorithm: for example for the tic-tac-toe
I have a simple question regarding T-SQL. I have a stored procedure which calls

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.