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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:07:50+00:00 2026-05-22T12:07:50+00:00

We are having a problem with a one-to-many mapping using property-ref. We are getting

  • 0

We are having a problem with a one-to-many mapping using property-ref. We are getting a ClassCastException because the type of the property-ref column is not the same as the type of the PK. It looks to be a known issue from googling. Any insight on a workaround or a better way to do this mapping would be appreciated.

Background:

  • 3 tables Account, User, UserAccount; One-to-many relationship between User and Account
  • Join table UserAccount has the full primary key of User and part of the primary key of Account.
  • One-to-many mapping for User to UserAccount which works as expected
  • Property-ref attribute to model the relationship between UserAccount and Account.
  • Found the following JIRA bug, indicating other people are experiencing the same issue with property-ref: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2052

I am using the following mapping files.
Account

<class name="com.model.Account" table="Account">
    <composite-id class="com.model.VersionId"
        mapped="false" name="id">
        <key-property column="entity_id" name="entityId" type="java.lang.Long" />
        <key-property column="entity_vers" name="version" type="java.lang.Long" />
    </composite-id>
    <property column="entity_id" name="entityId"
        type="java.lang.Long" insert="false" update="false" />

    <set name="userAccounts" cascade="none">
        <key column="entity_id" property-ref="entityId"/>
        <many-to-many class="com.model.UserAccount" column="acct_entity_id" property-ref="accountId"/>
    </set>
</class>

User

<class name="com.model.User" table="User">
    <composite-id class="com.model.VersionId"
        mapped="false" name="id">
        <key-property column="entity_id" name="entityId" type="java.lang.Long" />
        <key-property column="entity_vers" name="version" type="java.lang.Long" />
    </composite-id>
    <property column="user_name" length="255" name="name"
        type="java.lang.String" />

    <set name="userAccounts" table="UserAccount">
        <key>
            <column name="entity_id" />
            <column name="entity_vers" />
        </key>
        <one-to-many class="com.model.UserAccount" />
    </set>

</class>

UserAccount

<class name="com.model.UserAccount"
    table="UserAccount">
      <composite-id class="com.model.UserAccountId"
        mapped="false" name="id">
        <key-property column="entity_id" name="userId" type="java.lang.Long" />
        <key-property column="acct_entity_id" name="accountId"
            type="java.lang.Long" />
        <key-property column="entity_vers" name="userVersion"
            type="java.lang.Long" />
    </composite-id>

    <property column="acct_entity_id" name="accountId"
            type="java.lang.Long" insert="false" update="false"></property>

       <many-to-one name="user"
        class="com.model.User" insert="false"
        update="false">
        <column name="entity_id" />
        <column name="entity_vers" />
    </many-to-one>

    <set name="accounts" cascade="none">
        <key column="acct_entity_id" property-ref="acountId"/>
        <many-to-many class="com.model.Account" column="entity_id" property-ref="entityId"/>
    </set>
</class>

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-05-22T12:07:51+00:00Added an answer on May 22, 2026 at 12:07 pm

    For any-one who is interested I was able to solve this by using a unidirectional one-to-many mapping with join table from the User to the Account with the below mapping on the User for accounts

    <set name="accounts" table="UserAccounts">
            <key>
                <column name="entity_id" />
                <column name="entity_vers" />
            </key>
            <many-to-many column="acct_entity_id" property-ref="entityId" unique="true" class="com.model.Account" />
        </set>
    

    I have been able to test this out successfully, in case anyone else has such an issue in the future working with a legacy database.

    Some comments:
    Using unique=”true” allows you to use a many-to-many mapping where you would have had to use a one-to-many. This was important for me as I needed to be able to use property-ref in the mapping with is not allowed in one-to-many by hibernate DTD.

    Reference:
    http://docs.jboss.org/hibernate/core/3.3/reference/en/html/associations.html#assoc-unidirectional-join-12m

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

Sidebar

Related Questions

I am having problem with my Hibernate Mapping. I have a many to one
I'm having (many, but for now,) one problem with a project I'm working on.
Having problem in displaying relational properties b/w two tables having one(company) to many(package_master) relationship
I am having a problem with a page because its longer than one page
I am having problem with updating data to database. I have a simple many-to-one
forum member I am having one problem with the insertion of data using Hibernate
One problem that I am facing is having many queries with similar select statements
I am having one problem with the PHP json_encode function. It encodes numbers as
I'm having a problem with one of my functions within a template class. template
hi forum member I am having one problem with setting the radiofield in the

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.