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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T06:27:30+00:00 2026-05-30T06:27:30+00:00

I have a table Project with fields ID PROJECT_BASELINE_ATTRIBUTES_ID (FK for table PROJECT_BASELINE_ATTR) This

  • 0

I have a table Project with fields


ID
PROJECT_BASELINE_ATTRIBUTES_ID (FK for table PROJECT_BASELINE_ATTR)

This table has the following mapping


<hibernate-mapping package="com.initech.db.model">
    <class name="com.initech.db.model.Project" table="PROJECT">

        <id name="id" column="id" type="java.lang.Long">
            <meta attribute="use-in-tostring">true</meta>
            <generator class="sequence">
                <param name="sequence">PROJECT_ID_SEQ</param>
            </generator>
        </id>

        <many-to-one name="projectBaselineAttributes" column="PROJECT_BASELINE_ATTRIBUTES_ID" class="com.initech.db.model.ProjectBaselineAttributes" cascade="all" not-null="true">
            <meta attribute="use-in-tostring">true</meta>
        </many-to-one>^

     </class>
</hibernate-mapping>

The respective Project.java class has the fields


private Long id;
private ProjectBaselineAttributes projectBaselineAttributes;

Furthermore, I have a table PROJECT_BASELINE_ATTR, containing the field


ID

The Hibernate mapping:


<hibernate-mapping package="com.initech.db.model">
    <class name="com.initech.db.model.ProjectBaselineAttributes" table="PROJECT_BASELINE_ATTR">

        <id name="id" column="id" type="java.lang.Long">
            <generator class="sequence">
                <param name="sequence">PRO_BASE_ATTR_ID_SEQ</param>
            </generator>
        </id>

      <set name="projects" table="PROJECT" inverse="true" lazy="true" fetch="select">
          <key>
              <column name="PROJECT_BASELINE_ATTRIBUTES_ID" precision="22" scale="0" not-null="true" />
          </key>
          <one-to-many class="com.initech.db.model.Project" />
      </set>


    </class>
</hibernate-mapping>

The respective ProjectBaselineAttributes.java class has the fields


private Long id;
private Set projects = new HashSet();

The current mapping is not ideal, as the relationship between the two tables is actually one-to-one, but in the ProjectBaselineAttributes I have a set of Projects, even though there is always one Projet for one ProjectBaseLineattributes. What should the mapping look like for ProjectBaselineAttributes so that I can get the associated Project “singularly”, i.e. so that the class ProjectBaselineAttributes.java would look like this:


private Long id;
private Project project;
  • 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-30T06:27:31+00:00Added an answer on May 30, 2026 at 6:27 am

    Here’s the section of the Hibernate documentation which details how to map such a bidirectional one-to-one association using a foreign key.

    <class name="Person">
        <id name="id" column="personId">
            <generator class="native"/>
        </id>
        <many-to-one name="address" 
            column="addressId" 
            unique="true"
            not-null="true"/>
    </class>
    
    <class name="Address">
        <id name="id" column="addressId">
            <generator class="native"/>
        </id>
       <one-to-one name="person" 
            property-ref="address"/>
    </class>
    
    create table Person ( personId bigint not null primary key, addressId bigint not null unique )
    create table Address ( addressId bigint not null primary key )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table which has following fields project_name VARCHAR (100) running_frequency enum ('daily',
i have a project table which has a image_id field and a newsimage_id field.
I am designing a database for a project. I have a table that has
I have the following table structure, which is imported into an Entity Framework project:
I have a client table (with fields id, name) and a project table (with
I have nested model as following Project model has_many keywords and keyword belongs_to project
I have a table that has a bunch of fields. The fields can be
I have a table in SQL-server with projectcodes and sub-project-codes in the same fields.
i have a self referencing table called project that has a master detail relationship
I have a project table with projectId as primary key: **projectId**, projectName, dateCreated, etc.

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.