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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:39:25+00:00 2026-05-25T10:39:25+00:00

i’ve got two Entities with combinded primarky keys: @Entity @IdClass(APK.class) public class A {

  • 0

i’ve got two Entities with combinded primarky keys:

@Entity
@IdClass(APK.class)
public class A {
    @Id
    Integer pk1;

    @Id
    Integer pk2;

    @OneToMany(cascade = CascadeType.ALL, fetch=FetchType.EAGER,mappedBy="a")
    List<B> b = new ArrayList<B>();

    String name;
    ...
}

@Entity
@IdClass(BPK.class)
public class B {
    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumns({
        @JoinColumn(name = "pk1", referencedColumnName = "pk1"),
        @JoinColumn(name = "pk2", referencedColumnName = "pk2")
    })
    @Id 
    private A a;

    @Id
    Integer additional_key_part;

}

When i load the “A” class, the List is correctly loaded eagerly, the problem is, it does not work when i load the “B” class.

The “B” class will correctly use an Join with A, but only the PK fields of A will be populated (pk1, pk2), not the rest.

The real problem comes when the entity is send to a client which has no transaction, so no lazy loading possible. The only thing that seemed to work is to call a.getName() or something to start the lazy loading before closing the transaction, but this seems not really the correct way.

So, how to make sure the entity and all its childs are loaded ?

  • 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-25T10:39:26+00:00Added an answer on May 25, 2026 at 10:39 am

    Try changing the annotations to the following:

    @Entity
    @IdClass(ClassBPK.class)
    public class ClassB {
    
        @Id
        private Integer pk1;
        @Id
        private Integer pk2;
    
        @ManyToOne(fetch = FetchType.EAGER)
        @PrimaryKeyJoinColumns({
            @PrimaryKeyJoinColumn(name = "pk1", referencedColumnName = "pk1"),
            @PrimaryKeyJoinColumn(name = "pk2", referencedColumnName = "pk2")
        })
        private ClassA a;
    
        @Id
        private Integer pk3;
    
        //...
    }
    

    I run a quick check on OpenJPA 1.2.2 with Derby with a draft DAO class:

    logger.debug("Pre find");
    ClassB b = bDAOBean.findById(bId);
    logger.debug("Post find");
    logger.debug("A's name: {}", b.getA().getName());
    

    and I got:

    [DEBUG] Pre find 
    [INFO ] openjpa.Runtime - Starting OpenJPA 1.2.2 {main}
    // ... Here comes SQL from loading the entity
    [DEBUG] Post-find
    [DEBUG] A's name: nameA11
    

    There are no OpenJPA logs between the last two log lines, so it proves the whole ClassA was eagerly loaded.

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

Sidebar

Related Questions

i got an object with contents of html markup in it, for example: string
I've got a string that has curly quotes in it. I'd like to replace
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
public static bool CheckLogin(string Username, string Password, bool AutoLogin) { bool LoginSuccessful; // Trim
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I have a JSP page retrieving data and when single or double quotes are
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string

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.