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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T06:47:22+00:00 2026-06-11T06:47:22+00:00

I seem to be having an issue with mapping a collection in hibernate where

  • 0

I seem to be having an issue with mapping a collection in hibernate where the key and the resource are both entities to be mapped by hibernate.

Whereas from the documentation (my main resource for this issue has been this, but I of course welcome any others: http://docs.jboss.org/hibernate/orm/3.6/reference/en-US/html/collections.html) it would appear that this should be a relatively simple task, I just can’t seem to get the key of the map to persist.

My code as it stands looks like this:

Parent class:

@Entity
public class Parent {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private int id;
    @MapKey
    @MapKeyClass(Key.class)
    @ManyToMany(cascade = CascadeType.ALL)
    private Map<Key, Resource> map;

Key class:

@Table(name="ParentKey")
@Entity
public class Key implements Comparable<Key> {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private int id;
    @Column(name = "hierarchyKey")
    private int key;

The resource class is a relatively simple POJO and persists fine, so I would assume that the issue is not in that class.

I did come across the annotation @MapKeyManyToMany in some documentation on the hibernate forums, but I believe this has since been deprecated.

The schema of the database is unimportant at this stage, the main concern is simply making sure everything persists to the database. We’re using MySQL for the underlying database.

As I’m sure you can probably guess, any search involving the words map, hibernate, entity and key return a large amount of questions not related to this issue, though I’m sure this must be a situation that occurs quite often in terms of mapping situations.

I don’t often submit questions, but I am an active reader, so please let me know if any more info is required.

  • 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-11T06:47:23+00:00Added an answer on June 11, 2026 at 6:47 am

    This works as specified. Operations are not cascaded to the key of the map. They are cascaded only to the value. In documentation this is told with following words:

    When the target collection is a java.util.Map, the cascade element
    applies to the map value.

    Key must be persisted separately.

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

Sidebar

Related Questions

I am having an issue that I can't seem to figure out. Hopefully somebody
I am having an xslt issue that I cannot seem to solve. Right now
I am having a strange issue that I can't seem to resolve. Here is
I seem to be having an issue with PHP rounding (sort of) numbers by
I seem to be having an issue with Jax-WS and Jax-b playing nicely together.
I seem to be having an issue with Xalan's translate method. I have the
I seem to be having a strange issue with a 2D game I'm working
I'm having an issue with changing the attribute for an id and can't seem
thanks for looking. I'm having an issue i cant seem to get the submit
Seem to be having an issue with the tablesorter plugin and excluding columns for

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.