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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:32:05+00:00 2026-05-27T10:32:05+00:00

I have two MySQL tables: User (with an auto-incremented pk id) and WaitingUser which

  • 0

I have two MySQL tables: User (with an auto-incremented pk id) and WaitingUser which is a list of a subset of users. WaitingUsers table cannot contain more than one occurrence of a user so the column userId is PK.

public class User implements Serializable{
   private int id;
   private String userName;
....

TABLE USER:
id               int(10) unsigned PK
userName         varchar(45)

public class WaitingUser implements Serializable{
   private User userId;
   private String otherinfo;
....

TABLE WAITING_USER:
userId               int(10) unsigned PK
otherinfo            varchar(45)

Now I would like to map but I don’t know how to proceed.

The problem seems similar to the one reported here but I don’t use annotation:

Using an Entity (and their Primary Key) as another Entity's Id

How can I define the PK of WaitingUser is the PK of User in the WaitingUser.xbm.xml file?

  • 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-27T10:32:05+00:00Added an answer on May 27, 2026 at 10:32 am

    From the hibernate docs:

    You can map the id of a referenced class (primary key of a referenced table) to the id of the referencing class (primary key of the referencing table) with hbm.xml like this:

    <class name="WaitingUser">
      <id name="id">
        <generator class="foreign">
          <param name="property">userId</param>
        </generator>
      </id>
      <one-to-one name="userId" class="User" constrained="true"/>
    </class>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

using php and mysql I have two tables, a users table and a profiles
I have two tables on mysql: users, and management. The users table has a
Say I have two tables, users and groups each of which has an auto-incrementing
I have two MySQL tables like this: User Id (PK, auto-increment integer) Subscriber Id
I have two mysql tables: /* Table users */ CREATE TABLE IF NOT EXISTS
I have two tables in my MySQL database, users and tweets, as follows: TABLE
I have the following two mySQL tables with the 'child' table having a DELETE
I have two mysql tables: USER and ROSTER. Previously, I've been able to query
I have two tables users and items in a MySQL DB Users pk username
Ok, I have two MYSQL tables: CREATE TABLE `sessions` ( `id` int(11) NOT NULL

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.