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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T18:27:13+00:00 2026-06-11T18:27:13+00:00

I would like to create two table USER and USERDETAIL to fulfill: USERDETAIL have

  • 0

I would like to create two table USER and USERDETAIL to fulfill:

  1. USERDETAIL have reference to USER table.

  2. Operation on USER table do not need to aware of USERDEAIL table existence.

This should be one-to-one non bidirectional relationship.

The entity classes:

@Entity
@Table(name="USER")
public class User implements Serializable{  
    @Id 
    @Column(name="ID")
    @GeneratedValue(generator = "system-uuid") 
    @GenericGenerator(name = "system-uuid", strategy = "uuid")  
    private String id;  
    //...
}

@Entity
@Table(name="USERDETAIL")
public class UserDetail implements Serializable{    

    @Id 
    @Column(name="ID")
    @GeneratedValue(generator = "gen") 
    @GenericGenerator(name = "gen", strategy = "foreign",
    parameters = @Parameter(name = "property", value = "user"))
    private String id;

    @OneToOne(optional= false , targetEntity=User.class, cascade= CascadeType.ALL)
    @OnDelete(action = OnDeleteAction.CASCADE)
    //@JoinColumn(name="foreign_id",referencedColumnName="ID")
    @PrimaryKeyJoinColumn   
    private User user;  
    //...
}

This create two table correctly and the USERDETAIL have foreign key constraint that its primary key is refernece by USER’s id. However, the on Delete action is Restrict but not Cascade. I cannot delete a row of USER because of this.

I am using MySQL Sever 5.1. It does not seem like it does not support on delete action is cascade. Because I can manually delete the constraint and add a new constraint that set to on delete is cascade and work as I expected.

  • 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-11T18:27:14+00:00Added an answer on June 11, 2026 at 6:27 pm

    Finally, I have solved the problem.

    First of all, I have follow http://www.mkyong.com/hibernate/hibernate-one-to-one-relationship-example-annotation/ to create oneToOne mapping entities.

    However, when I start the Tomcat, it always throw NullPointerException on mapping. Therefore, I come up with my question entities and seem to work fine except the deletion.

    I finally realize it is just a bug that hibernate-anoatation cause. I then use 3.4.0.ga version and follow the link again. By replace @GeneratedValue(strategy = IDENTITY) (I don’t know why using this, hibernate cannot create table) to

    @GeneratedValue(generator = "system-uuid") 
    @GenericGenerator(name = "system-uuid", strategy = "uuid") 
    

    it work as I expected.

    Although there is no foreign-key constrain on the table, deleting owner (USER) table really can also delete the child (USERDETAIL) table correctly with hibernate handle.

    I also do not need to worry about update owner table with no child field on it. The mappedBy side actually has no physical mapping defined as Khue Vu said. Hibernate is smart enough not to delete the relation.

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

Sidebar

Related Questions

I have implemented two classes, isbn10 and isbn13. I would like to create a
I have two different .Net projects, hosted on github. I would like to create
I have an HTML Table and would like to allow the user to click
I would like to create a multi-dimensional array with two variables but don't know
I would like to create a UIBarButtonItem on my iPhone application which has two
i would like create a array of structure which have a dynamic array :
I'm developing a form that I would like the user to have the option
I have two DB real and backDB. I would like to copy everything from
I have two ways of doing a similar thing and would like to know:
I would like to create this shape using just css. I am pretty sure

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.