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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T01:46:46+00:00 2026-06-06T01:46:46+00:00

This is my Database structure, One-to-One mapping in MySQL: This is my java file:

  • 0

This is my Database structure, One-to-One mapping in MySQL:

DB Schema

This is my java file:

public class Employee {

private EmployeeDetail empdetail;
private String firstname;
private String lastname;

// getters and setters 

}


public class EmployeeDetail {
    private Employee employee ;
    private int employee_id;
    private String street;
    private String city;
    private String state;
    private String country;

// getters and setters 

}

This is my mapping file:

<hibernate-mapping>

     <class name="Employee" table="employee">
        <id name="employee_id"  type="java.lang.Integer"  column="employee_id">
            <generator class="assigned" />
        </id>
        <one-to-one name="empdetail" class="EmployeeDetail"
            cascade="all"></one-to-one>

        <property name="firstname" type="java.lang.String" column="firstname" />
        <property name="lastname" type="java.lang.String" column="lastname" />

    </class>



 <class name="EmployeeDetail" table="employeedetail">
        <id name="employee_id" type="java.lang.Integer"  column="employee_id">
       <generator class="foreign">
                <param name="property">employee</param>
            </generator>
        </id>
        <one-to-one name="employee" class="Employee"
            cascade="save-update"></one-to-one>

        <property name="street"  type="java.lang.String" column="street" />
        <property name="city" type="java.lang.String" column="city" />
        <property name="state" type="java.lang.String" column="state" />
        <property name="country" type="java.lang.String" column="country" />

 </class>

</hibernate-mapping>

This is my client program:

Session session = factory.openSession();
        Transaction tx = session.beginTransaction();

        EmployeeDetail edetail = new EmployeeDetail();
        edetail.setCity("Hyd");
        edetail.setCountry("India");
        edetail.setEmployee_id(222);
        edetail.setState("Andhra Pradesh");

        Employee employee = new Employee();

        employee.setEmployee_id(222);
        employee.setFirstname("Pavan");
        employee.setLastname("Jaooi");
        employee.setEmpdetail(edetail);

        session.merge(employee);
        tx.commit();
        session.close();
        factory.close();

This is the exception I am getting:

INFO: Not binding factory to JNDI, no JNDI name configured
Hibernate: select employee0_.employee_id as employee1_0_1_, employee0_.firstname as firstname0_1_, employee0_.lastname as lastname0_1_, employeede1_.employee_id as employee1_1_0_, employeede1_.street as street1_0_, employeede1_.city as city1_0_, employeede1_.state as state1_0_, employeede1_.country as country1_0_ from employee employee0_ left outer join employeedetail employeede1_ on employee0_.employee_id=employeede1_.employee_id where employee0_.employee_id=?
Hibernate: select employeede0_.employee_id as employee1_1_0_, employeede0_.street as street1_0_, employeede0_.city as city1_0_, employeede0_.state as state1_0_, employeede0_.country as country1_0_ from employeedetail employeede0_ where employeede0_.employee_id=?
Exception in thread "main" org.hibernate.id.IdentifierGenerationException: attempted to assign id from null one-to-one property: employee
    at org.hibernate.id.ForeignGenerator.generate(ForeignGenerator.java:44)
    at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:99)
    at org.hibernate.event.def.DefaultMergeEventListener.entityIsTransient(DefaultMergeEventListener.java:186)
    at org.hibernate.event.def.DefaultMergeEventListener.entityIsDetached(DefaultMergeEventListener.java:240)
    at org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:120)
    at org.hibernate.impl.SessionImpl.fireMerge(SessionImpl.java:687)
    at org.hibernate.impl.SessionImpl.merge(SessionImpl.java:669)
    at org.hibernate.engine.CascadingAction$6.cascade(CascadingAction.java:245)
    at org.hibernate.engine.Cascade.cascadeToOne(Cascade.java:268)
    at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:216)
    at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:169)
    at org.hibernate.engine.Cascade.cascade(Cascade.java:130)
    at org.hibernate.event.def.AbstractSaveEventListener.cascadeAfterSave(AbstractSaveEventListener.java:456)
    at org.hibernate.event.def.DefaultMergeEventListener.entityIsTransient(DefaultMergeEventListener.java:194)
    at org.hibernate.event.def.DefaultMergeEventListener.entityIsDetached(DefaultMergeEventListener.java:240)
    at org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:120)
    at org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:53)
    at org.hibernate.impl.SessionImpl.fireMerge(SessionImpl.java:677)
    at org.hibernate.impl.SessionImpl.merge(SessionImpl.java:661)
    at org.hibernate.impl.SessionImpl.merge(SessionImpl.java:665)
    at CustomerClient.main(CustomerClient.java:31)
  • 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-06T01:46:48+00:00Added an answer on June 6, 2026 at 1:46 am

    You told Hibernate to generate the EmployeeDetail ID from the ID of its employee property, but you never initialized this property.

    Add edetail.setEmployee(employee); to your code.

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

Sidebar

Related Questions

alt text http://produits-lemieux.com/database.jpg This is basicly my database structure one product (let say soap)
I have this database structure, SET SQL_MODE=NO_AUTO_VALUE_ON_ZERO; CREATE TABLE IF NOT EXISTS `announces` (
this is my database structure for my terms table (categories): id | name |
My database structure looks something like this: Person Id Name FieldA FieldB Phone Id
I have created a table on an Oracle 10g database with this structure :
I have this table structure on a SQL Server 2008 R2 database: CREATE TABLE
this is a part from my database structure: Table: Item Columns: ItemID, Title, Content,
With the following simple relational database structure: An Order has one or more OrderItems,
I use entity Framework 4.2 and MVC 4 I Got this model/Database structure UserInformation
I have an existing database structure created outside or Rails. I've edited one of

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.