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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T16:04:23+00:00 2026-05-12T16:04:23+00:00

These are the tables I want to map using Hibernate: user (PK UserId) article

  • 0

These are the tables I want to map using Hibernate:

user (PK UserId)
article (PK ArticleId, FK CreatorUserId)
category (PK CategoryId, FK ParentCategoryId)

I have been looking at the documentation for Hibernate, but I really cannot choose what type of mapping is the most suitable for my tables.

Any help would be greatly appreciated! 🙂

  • 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-12T16:04:23+00:00Added an answer on May 12, 2026 at 4:04 pm

    For user-articles relationship you can use either Set or List mapped as bag; List tends to be a bit more convenient to deal with on java side especially if article has an attribute by which you may want to sort the collection (e.g. creation date). Sample mapping is:

    <!-- within User mapping -->
    <set name="articles" table="article" inverse="true">
      <key column="CreatorUserId"/>
      <one-to-many class="Article"/>
    </set>
    
    <!-- within Article mapping -->
    <many-to-one name="creatorUser" class="User" column="CreatorUserId" not-null="true"/>
    

    The above maps association as bidirectional with Article being responsible for maintaining the relationship (this avoids an unnecessary update during collection changes). Details are here. Replace <set> with <bag> if you’d rather use List in place of Set; you can then add “order-by” attribute to have your list sorted in the database.

    For Category you could in theory do the same, however if your category hierarchy is deep and you need to retrieve specific levels / sub-trees rather often, consider using nested set model instead.

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

Sidebar

Related Questions

I have a class hierarchy that I want to map across several tables using
I have two mysql tables and i want to merge the results of these
I have two tables, tbl_foo and tbl_bar , and I want to join these
I have a class to map a table for using hibernate. There are some
I have two tables that I want to join together. Table1 Year, ID, Theme,
I have a table Sample and another SampleLog With these structure I want to
i have a stack of messages in database table. i want to send these
I am using hibernate and i want to display only those records of table
I have a simple POJO mapped to a table using Hibernate. Which works just
I want to map SQL query to Business object using Nhibernate . There are

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.