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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:25:45+00:00 2026-05-26T10:25:45+00:00

Below is the my complete code Here is cfg file <hibernate-configuration> <session-factory> <!– Database

  • 0

Below is the my complete code

Here is cfg file

<hibernate-configuration>
<session-factory>
    <!-- Database connection settings -->
    <property     name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
    <property   name="hibernate.connection.url">jdbc:oracle:thin:@localhost:1521:xe</property>
    <property name="hibernate.connection.username">MyProject1</property>
    <property name="hibernate.connection.password">tingtong</property>
    <property name="hibernate.default_schema">MyProject1</property>


    <!-- JDBC connection pool (use the built-in) -->
    <property name="connection.pool_size">1</property>

    <!-- SQL dialect -->
    <property name="hibernate.dialect">org.hibernate.dialect.OracleDialect</property>

      <property name="hibernate.hbm2ddl.auto" >update</property>

    <!-- Echo all executed SQL to stdout -->
    <property name="show_sql">true</property>

    <!-- Mapping files -->
    <mapping resource="Person.hbm.xml"/>
   </session-factory>
 </hibernate-configuration>

Below is the mapping file

<hibernate-mapping>

 <class name="com.daasl.Person" table="person">
  <id name="id" type="int">
     <generator class="increment"/>
  </id>

  <property name="name" column="cname" type="string"/>
  <one-to-one name="address" class="com.daasl.Address" property-ref="personId"   cascade="all"/>

  </class>


 <class name="com.daasl.Address" table="Address">
  <id name="id" type="int">
     <generator class="increment"/>
  </id>

    <!--for one to one -->
      <property name="personId"  type="int"/> 
  <property name="addressLine1"  type="string"/>

 </hibernate-mapping>

below is the person Value object

public class Person implements Serializable {

private int id;
private String name;
//private int addressId;
private Address address;
// getter seeter for each field
}

below is address value object

 public class Address {

private int id;
private int personId;
private String addressLine1;
// getter seeter for each field

}

Below is the code snippet from main method

tx = session.beginTransaction();
            person = (Person)session.get(Person.class, 4);

        // Create a Person object and save it
        Person p1 = new Person();
        p1.setName("Scott");
        Address add1= new Address();
        add1.setAddressLine1("NY1");
        p1.setAddress(add1);
        session.save(p1);


     //   p1.setName("mohit1");
        // Retrieve the person objects
         person = (Person)session. get(Person.class,1);

        tx.commit();
        tx = null;

As above code when I save Person object I expect address object to be saved also alongwith correponding personid. When I run above program personid is going as 0 in personid column inside address table. as per my understanding personid should be inserted with with person table id value. Right?

Second thing I wanted to know is : Does one to one mapping create foreign-child key relation. As in above example I was expecting personid column inside address table should point to primary key of person table i.e id column. But it did not create any foreign key constraint on personid column of address table.

Am I missing something here

  • 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-26T10:25:46+00:00Added an answer on May 26, 2026 at 10:25 am

    Yes, you’re missing something. The point of an ORM like hibernate is to be able to implement associations between objects.

    Either make the association unidirectional, and remove the personId field from Address, or make it bidirectional, and replace the personId field by a person field, of type Person. In this case, one side of the association (the person.address side) will have to be the inverse of the other one (the adress.person side).

    This is described in the Hibernate reference documentation. Read it. See http://docs.jboss.org/hibernate/core/3.6/reference/en-US/html_single/#assoc-unidirectional-121 for unidirectional one-to-one and http://docs.jboss.org/hibernate/core/3.6/reference/en-US/html_single/#assoc-bidirectional-121 for bidirectional one-to-one.

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

Sidebar

Related Questions

Below is the complete code of the jquery AJAX tab script I am working
What is the simplest, fastest way to complete the PHP code below such that
Below is a complete html page that shows the problem. The myDiv should be
Below is the code of a simple html with a table layout. In FF
Compile error in vs2010(Win32 Console Application Template) for the code below. How can I
I have a gridview that gets created in codebehind. In the below code, I
See the code below. If I initialize more than one entity context, then I
Using the below code, my template loads fine until I submit the from, then
Inn the below code i have placed my mp3 in the src directory where
In the below code how will in action script how will i say that

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.