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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T19:03:16+00:00 2026-05-15T19:03:16+00:00

Maybe somebody can clarify what is wrong with the code below. When I create

  • 0

Maybe somebody can clarify what is wrong with the code below. When I create one-to-one association within embedded class (it is composite primary key) like in the code below:

@Entity
public class Test {

    @EmbeddedId
    private TestId id;

    @Embeddable
    public static class TestId implements Serializable {
        private static final long serialVersionUID = 1950072763330622759L;

        @OneToOne(optional = false)
        @JoinColumn(name = "linkedTable_id")
        private LinkedTable linkedTable;

    }
    ..........
}

I get the following stack trace:

--------------------------------------------

Caused by: java.lang.NullPointerException
    at org.hibernate.cfg.AnnotationBinder.bindOneToOne(AnnotationBinder.java:1867)
    at org.hibernate.cfg.AnnotationBinder.processElementAnnotations(AnnotationBinder.java:1286)
    at org.hibernate.cfg.AnnotationBinder.fillComponent(AnnotationBinder.java:1662)
    at org.hibernate.cfg.AnnotationBinder.bindId(AnnotationBinder.java:1695)
    at org.hibernate.cfg.AnnotationBinder.processElementAnnotations(AnnotationBinder.java:1171)
    at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:706)
    at org.hibernate.cfg.AnnotationConfiguration.processArtifactsOfType(AnnotationConfiguration.java:452)
    at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:268)
    at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1121)
    at org.hibernate.ejb.Ejb3Configuration.buildMappings(Ejb3Configuration.java:1211)
    at org.hibernate.ejb.EventListenerConfigurator.configure(EventListenerConfigurator.java:154)
    at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:847)
    at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:178)
    at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:235)
    ... 26 more

What is interesting why the sample above works if I change association type to many-to-one and doesn’t work with one-to-one?

  • 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-15T19:03:17+00:00Added an answer on May 15, 2026 at 7:03 pm

    I wasn’t aware this was possible but, according to the Hibernate Annotation reference documentation, it is (this is Hibernate specific though):

    2.2.3.2.1. @EmbeddedId property

    (…)

    While not supported in JPA, Hibernate
    lets you place your association
    directly in the embedded id component
    (instead of having to use the
    @MapsId annotation).

    @Entity
    class Customer {
      @EmbeddedId CustomerId id;
      boolean preferredCustomer;
    }
    
    @Embeddable
    class CustomerId implements Serializable {
      @OneToOne
      @JoinColumns({
        @JoinColumn(name="userfirstname_fk", referencedColumnName="firstName"),
        @JoinColumn(name="userlastname_fk", referencedColumnName="lastName")
      }) 
      User user;
      String customerNumber;
    }
    
    @Entity 
    class User {
      @EmbeddedId UserId id;
      Integer age;
    }
    
    @Embeddable
    class UserId implements Serializable {
      String firstName;
      String lastName;
    }
    

    And with the code you provided, the following snippet just works for me:

    LinkedTable linkedTable = new LinkedTable();
    linkedTable.setId(1l);
    session.persist(linkedTable);
    session.flush();
    
    Test.TestId testId = new Test.TestId();
    testId.setLinkedTable(linkedTable);
    Test test = new Test();
    test.setId(testId);
    session.persist(test);
    session.flush();
    

    Tested with Hibernate EM 3.4.0.GA, Hibernate Annotations 3.4.0.GA and Hibernate Core 3.3.0.SP1.

    If it doesn’t work for you, can you provide a bit more code allowing to reproduce the problem?

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

Sidebar

Related Questions

Maybe somebody can help me. Starting with a CSV file like so: Ticker,Price,Market Cap
This is baffling me, maybe somebody can shine the light of education on my
Maybe somebody can help me. In my project I'm using a linked list with
I am having some trouble with this regular expression, Can somebody maybe assist me
Maybe somebody can help explain why I am getting a null value when converting
Possible Duplicate: What does the || operator do? Maybe somebody can provide a better
UPDATE AT THE BOTTOM Maybe somebody could help with this... been struggling with it
Maybe I just can't figure out the right keywords to get an answer out
Maybe it's because of the dark outside, but I can't get this Position geom_text
Maybe it's wrong but I always use this query for my app: cme_only =

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.