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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T03:29:29+00:00 2026-06-18T03:29:29+00:00

I have a class Event containing a composite primary key (start date and end

  • 0

I have a class Event containing a composite primary key (start date and end date).

A EventPlanning class holds a Set of such Event objects and has to persist them using hibernate with XML.
I can do this for classes with a common primary key:

<!-- EventPlanning xml -->
....
<id name="id" column="id">
<generator class="native" />
</id>
<property name="name" column="name" type="string" update="false" />

<set name="events" table="events" cascade="all">
    <key column="event_id">   // ###### here! ######
    </key>
    <one-to-many class="myPackage.Event" />
</set>
...

but I can’t find out how this works with a composite key..

replacing the <key column="event_id"> with the following code doesn’t work:

<key>
    <property column="start_date" />
    <property column="end_date" />
</key>

I’d be glad if somebody can show me the right syntax! 🙂

the Event xml looks like this:

<class name="myPackage.Even" table="events">

        <composite-id>
            <key-property name="startDate" column="start_date" type="date" />
            <key-property name="endDate" column="end_date" type="date" />
        </composite-id>

        <property name="signinDeadline" column="signin_deadline"
            type="date" />
        <property name="confirmationDeadline" column="confirmation_deadline"
            type="date" />

        <set name="participants" table="participants" cascade="all">
            <key column="event_id">
            </key>
            <one-to-many class="myPackage.Participants" />
        </set>

    </class>

thanks in advance! 🙂

  • 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-18T03:29:31+00:00Added an answer on June 18, 2026 at 3:29 am

    After having now worked longer with JPA and Hibernate, I’d just say that you simply should not use composite primary keys. Caches use ids as keys that point to cached values, data retrieving methods like get and load expect the id as parameter etc.
    The advantages gained by having an id field pay off against the additional space it needs.

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

Sidebar

Related Questions

In my partial class containing the DataSet event I have the following: protected override
I have a class (or function-containing object; I've heard that there is no such
I have this code : class Event{}; class CustomEvent:public Event{}; class Handler { public:
I have following event class. I have a question related to the Property method
I have an Event class. Due to the way dates are handled, we need
I have a class with an event: public event MyEventHandler MyEvent; Is there any
I have defined an Event class: Event and all the following classes inherit from
I have a class essentially: public class WindowEvent extends Event { public static const
Say you have a class with an event property. If you instantiate this class
I have class A, which exposes an event. an object of class B subscribed

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.