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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T17:28:53+00:00 2026-05-28T17:28:53+00:00

@Entity @Table(name = parent) public final class Parent extends Base { @OneToOne(cascade = CascadeType.PERSIST,

  • 0
@Entity
@Table(name = "parent")
public final class Parent extends Base {

@OneToOne(cascade = CascadeType.PERSIST, fetch = FetchType.EAGER)
private Person person;

and doing (amongst other things) this :

Parent parent = new Parent();
Person person = new Person();
parent.setPerson(person);
session.save(parent);

I get the mentioned exception ?

Do I manually need to call session.save(person) before ? do I have to add a cascade type annotation to the childs class definition(where it references the parent) ?

Or have I missed something else obvious ?

I don’t want to use CascadeType.ALL as when a parent is deleted I want to keep the person(child).

Both entities/tables extend a common Base table :

@MappedSuperclass()
public abstract class Base {

    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    private Integer id;

    public Integer getId() {
    return id;
    }

Will this effect which cascade type is required ?

  • 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-28T17:28:54+00:00Added an answer on May 28, 2026 at 5:28 pm

    You haven’t mentioned the Hibernate version, but this hasn’t changed since I ever started using it.

    As you can read in the Hibernate reference, to get the Java standard SAVE_UPDATE you need {CascadeType.PERSIST, CascadeType.MERGE} in Hibernate.

    EDIT: Seeing the updated info, what you’re doing now causes Hibernate to treat it as a bi-directional one-to-one mapping. This basically means that for each object in any of those two tables, there has got to be a counterpart in the other table with the same ID. Therefore, you cannot delete only one of them, you would lose FK integrity.

    If you want it to be a unidirectional mapping, e.g., if you want to be able to delete the person but leave the parent — you have to specify a FK, usually via @JoinColumn, like
    @JoinColumn(name="PERSON_ID", unique=false, nullable=true, insertable=true, updatable=true)

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

Sidebar

Related Questions

I have a parent-child relationship: @Entity @Table(name = user) public final class User {
Here is the BlogPost model : @Entity @Table(name = blog_posts) public class BlogPost extends
I have the following property defined: @Entity @Table(name = person) public class Person extends
Consider the following code: @Entity @Table(name = a) public class A implements Serializable {
Hi every one I have these classe @Entity @Table(name = login, uniqueConstraints={@UniqueConstraint(columnNames={username_fk})}) public class
I have the following (simplified) Hibernate entities: @Entity @Table(name = package) public class Package
I have a Category class which looks like this: @Entity @Table(name = categories) public
We are trying to use a basic @OneToMany relationship: @Entity @Table(name = PARENT_MESSAGE) public
I am having problems performing a cascade persist operation on a parent entity. When
Supposing these are my parent and my child objects: Parent: @Entity @Table( name =

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.