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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T22:29:54+00:00 2026-05-17T22:29:54+00:00

This is a Hibernate/JPA question. I have a set of Schedule objects, each including

  • 0

This is a Hibernate/JPA question.

I have a set of Schedule objects, each including several Steps of various StepTypes. Each StepType is unique within a schedule, so the steps are stored as a Map<StepType, Step>. The code is annotated as:

@Entity
public class Schedule implements Serializable {
    @MapKey(name="type")
    @OneToMany(cascade=CascadeType.ALL, mappedBy="schedule")
    private Map<StepType, Step> steps;
}

@Entity
@Table(uniqueConstraints={@UniqueConstraint(columnNames={"schedule", "type"})})
public class Step implements Serializable {
    @ManyToOne
    private StepType type;

    @ManyToOne
    private Schedule schedule;
}

Unfortunately, this is apparently not allowed. A MapKey is required to have a uniqueness constraint associated with it, which type does not, since step type is only unique within a particular schedule.

Is there a better way to annotate this structure, or am I going to have to rethink the object model for Hibernate’s sake? Or should this violation be harmless? (The Map is refusing to load properly, but I can’t confirm for sure that this is why.)

  • 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-17T22:29:55+00:00Added an answer on May 17, 2026 at 10:29 pm

    According to the spec, you’re right, uniqueness is required. But according to me (and you), it would seem logical to only require “localized uniqueness”.
    I’ve just found that the “Pro JPA 2” Book states the same: “not required to be unique across the entire domain of this entity type. It only need to be unique within the scope of the relationship”.

    I need the exact same behavior as you. I’ll test code soon.

    Here’s a link to the excerpt of the book:
    http://books.google.com/books?id=j84hdeHH2PYC&pg=PA119&lpg=PA119&dq=jpa+mapkey+uniqueness&source=bl&ots=C_TluOiJxZ&sig=EibqwD-3slqk7pnEJDK38k4T6Zc&hl=fr&ei=147MTJLTHNC6jAecuanYBw&sa=X&oi=book_result&ct=result&resnum=9&ved=0CEgQ6AEwCA#v=onepage&q=t%20should%20also%20be%20unique%2C%20although%20it%20is%20not%20&f=false

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

Sidebar

Related Questions

I have been using Hibernate Restrictions in JPA 1.0 ( Hibernate driver ). There
We have a server application that exposes a certain model, and set of services
I am using Hibernate (JPA) with Derby database - my app server is Jboss
I have a user object represented in JPA which has specific sub-types. Eg, think
I am working currently on creation of some tests on my app. I have
I have group and user where group must have an owner otherwise he couldn't
I have the following code (OLE = OptimisticLockException) ... public void outer() { try
I've hit a blocker adding a fix to an existing project.the main problem is
I want to be a J2EE architect in future. I started learning new technologies

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.