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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:59:18+00:00 2026-05-24T23:59:18+00:00

When trying to save an ID from my parent class into a child class,

  • 0

When trying to save an ID from my parent class into a child class, I keep getting the error
“ERROR – Field ‘parent_id’ doesn’t have a default value”

I have tried all types of mappings. I am using annotations.

Any help on this would be appreciated

Parent:

      @Id
      @Column(name="id")
      @GeneratedValue(strategy=GenerationType.AUTO)
      private long id;
      @Column(name="description")
      private String description;
      @OneToMany
      @Cascade(value= {org.hibernate.annotations.CascadeType.SAVE_UPDATE, org.hibernate.annotations.CascadeType.DELETE})
      @JoinColumn(name="parent_id")
      private List<Child> children;

Child:

  @Id
  @Column(name="id")
  @GeneratedValue(strategy=GenerationType.AUTO)
  private long id;
  @Column(name="description")
  private String description;

Thanks.

  • 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-24T23:59:18+00:00Added an answer on May 24, 2026 at 11:59 pm

    You must have something wrong somewhere else because those mappings will work the way they are. They could be better, but they’ll work. Specifically, all the @Column annotations are redundant and unnecessary, and as non sequitor noted, you should use the cascade property of JPA’s @OneToMany instead of Hibernate’s @Cascade. I’ve created a runnable example with the cleaned-up version of what you posted. If you have git and maven, you can run it with:

    git clone git://github.com/zzantozz/testbed tmp
    cd tmp
    mvn -q compile exec:java \
        -Dexec.mainClass=rds.hibernate.UnidirectionalManyToOneJoinColumn \
        -pl hibernate-unidirectional-one-to-many-with-join-column
    

    It creates a parent with two children, saves them, and then loads them and prints out the graph. The output is:

    Creating parent with two children
    Loading saved parent
    Parent{description='parent', children=[Child{description='child 2'}, Child{description='child 1'}]}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose we have 2 classes, Child, and the class from which it inherits, Parent.
I'm trying to save the returned data from HTTP request into a variable. The
I am trying to save data into the same table several times from the
Here is my model_users class (the model it extends from doesn't have anything yet
I am trying to save image from fileupload control into the database public Byte[]
In a situation where you have a parent class which has one child class,
I'm trying to save some layouts from DevExpress Grid Controls so that users can
I am trying to save my data from a view that was loaded on
I'm trying to save an excel spreadhseet from SQL Server Integration Services 2005. Unfortunatly
I'm trying to save the site that a user came from when they sign

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.