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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T19:53:06+00:00 2026-06-11T19:53:06+00:00

I have to create complex hibernate mapping. The following simplified example explains my problem.

  • 0

I have to create complex hibernate mapping. The following simplified example explains my problem.

I have two entities:

public class Work {

  private WorkType type;
  private Set<Workers>;
  ...
}

public class Worker {

  private Map<WorkType,Work>;
  ...
}

I have 3 tables:

t_works columns: id, type,...
t_workers columns: id,...
t_work_worker columns: worker_id, work_id.

I want to map the map with hibernate, without copying the type values to t_work_worker.
The problem here is that the map key (WorkType) is a part of the map value (Work).

My hibernate hbm:

<typedef class="org.hibernate.type.EnumType" name="workType">
   <param name="enumClass">myPackage.WorkType</param> 
   <param name="type">12</param> 
</typedef>

<class name="work" table="T_WORKS">
    <property name="type" type="workType" column="type"/>
    <set name="workers" table="T_WORK_WORKER" inverse="true" lazy="false" cascade="none">
        <key column="WORK_ID" />
        <many-to-many column="WORKER_ID"class="myPackage.Worker"/>
    </set>
</class>

<class name="Worker" table="T_WORKERS">
    <map name="channels" table="T_WORK_WORKER" lazy="false" cascade="all">
       <key column="WORKER_ID" />                        
       <map-key formula="(select w.TYPE from t_works w where w.ID=WORK_ID)"type="workType"/>
       <many-to-many column="WORK_ID" class="myPackage.Work"/>
    </map>
</class>

This mapping works but requires additional select statement (see formula atribute).
I wonder whether there’s a way to map the work type as a key, without using “formula” and without adding the type column to the relations table.

  • 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-11T19:53:07+00:00Added an answer on June 11, 2026 at 7:53 pm

    As you said, part of your problem is that you have a circular reference. This is usually not a very good idea, so you might want to think of an alternative structure. Do you really need the circular reference? Why does the worker need to have a map of worktype and work? I would probably make the connection between worker and work in another class, so you won’t need the circular reference.

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

Sidebar

Related Questions

I have create a Java class extending LinearLayout as shown below public class CustomLinear
I have create a Java class extending LinearLayout as shown below public class News
I have two classes: public class Reference { public virtual string Id { get;
I'm have a fair complex Form that I am trying to create in Play
I have create my own NSOpenGLView class, right now the data that i want
We have a complex business model and is using NHibernate to create and maintain
I have a curious little problem. I have a service that needs to create
I have the following situation. A customer uses JavaScript with jQuery to create a
I have the need to create a complex predicate for an abstract base object.
I have to create a mobile application which will work on diffrent mobile platforms:

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.