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

The Archive Base Latest Questions

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

I am using eclipselink for JPA . I have an entity, which has a

  • 0

I am using eclipselink for JPA. I have an entity, which has a composite key fabricated out of two fields. Following is my Embeddable primary key class’ fields(members).

    @Embeddable
    public class LeavePK {
       @ManyToOne(optional = false)
       @JoinColumn(name = "staffId", nullable = false)
       private Staff staff;
       @Temporal(TemporalType.TIMESTAMP)
       private Calendar date;
       //setters and getters
    }

My entity is going to hold leave data related to a staff, so I am trying to combine staff object and leave date to produce composite key. Apart from my logic, it is not allowing me to have a foreign key mapping inside embeddable class. When I try to use JPA tools–> Generate Tables From Entity, it gives error as below, which explains, but I am not getting it.

org.eclipse.persistence.exceptions.ValidationException
Exception Description: The mapping [staff] from the embedded ID class [class rs.stapp.entity.LeavePK] is an invalid mapping for this class. An embeddable class that is used with an embedded ID specification (attribute [leavePK] from the source [class rs.stapp.entity.Leave]) can only contain basic mappings. Either remove the non basic mapping or change the embedded ID specification on the source to be embedded.

Does it mean, I cannot have a key(from composite key) which is also a foreign key. Is there a alternative way to accomplish this ERM? Please help. Thanks

  • 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-01T15:04:29+00:00Added an answer on June 1, 2026 at 3:04 pm

    Don’t put relationships into ID classes, neither for @IdClass or @EmbeddedId ones. An @Embeddable class may only include the annotations @Basic, @Column, @Temporal, @Enumerated, @Lob, or @Embedded. Everything else is provider-specific syntax (e.g. Hibernate allows this, but since you’re using EclipseLink, which is the JPA RI, I doubt this is what you want).

    Here’s an example JPA PK/FK mapping:

    @Entity
    @Table(name = "Zips")
    public class Zip implements Serializable
    {
        @EmbeddedId
        private ZipId embeddedId;
    
        @ManyToOne
        @JoinColumn(name = "country_code", referencedColumnName = "iso_code")
        private Country country = null;
    
        ...
    }
    
    @Embeddable
    public class ZipId implements Serializable
    {
        @Column(name = "country_code")
        private String countryCode;
    
        @Column(name = "code")
        private String code;
    
        ...
    }
    

    HTH

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

Sidebar

Related Questions

I have entity model like this (using EclipseLink and JPA 2.0): @Entity class A
I'm using JPA 2.0, more precisely Eclipselink. Here's my problem: I have an entity
I'm using the EclipseLink implementation of the JPA 2.0 which allows pessimistic locking. I
Using EclipseLink 2.3.2 with static weaving (Maven plugin) against OracleXE. I have the following
I'm using spring mvc 3.0 with eclipselink and jpa and I'm experiencing following issue:
I have a running web service (using EclipseLink as JPA provider) and would like
I'm using EclipseLink as the JPA provider. Further I'm using the following TABLE_PER_CLASS inheritance
This is similar to How to cascade persist using JPA/EclipseLink I have to entities
I am developing a web application using JSF and JPA(Eclipse link). I have two
I have been developing my web-app using JPA 2.0 implementation EclipseLink 2.2.0. I finally

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.