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

  • Home
  • SEARCH
  • 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 7880563
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T04:10:32+00:00 2026-06-03T04:10:32+00:00

I have a table with five columns. The two columns, together, make up the

  • 0

I have a table with five columns. The two columns, together, make up the primary key of my table. I’m trying to instantiate an Entity class that corresponds to that table using hibernate. The problem is how do I tell hiberante that the primary key is not just a single field of the class but two. I don’t want hiberante to create the database schema for me as I have already crated it with all the necessary primary key settings.

I have read about the composite-key but it think that is not suitable for me. After all, I only have one table and there won’t be one-to-many or similar cardinality in my code.

I tried something like this which apparently ain’t working.

    <?xml version="1.0"?>
    <!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
    <hibernate-mapping>
       <class name="blog.Message" table="MESSAGES">
       <id name="title" column="MESSAGE_TITLE"></id>
       <id name="author" column="MESSAGE_AUTHOR"></id>
       <property name="body" column="MESSAGE_BODY"/>
         // ....AND TWO MORE FIELDS

    </class>
    </hibernate-mapping>

What is the way to do it? Is composite-key a must?
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-03T04:10:33+00:00Added an answer on June 3, 2026 at 4:10 am

    Ideally you should avoid natural keys with hibernate, if at all possible. Hibernate will work much better if you create a single id column, that hibernate can use to manage the identity of the row.

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

Sidebar

Related Questions

I have a simple mysql table with five columns: id: auto_increment (primary) id_symbol: INT(4)
I am trying to build a table in latex where five columns have a
I have table with a unique auto-incremental primary key. Over time, entries may be
I have a table with a list of names spread across five different columns.
I have a table with data : id one two three four five six
I created a table with five columns dynamically. Two (the second and third column)
I have a table layout with five columns and many rows with dynamic content.
So I have table with only two, long-ish columns. I want the display the
I have one table in sqlite database which contains five different columns as shown
I have a main table with a primary key and a partition column (a

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.