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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T01:31:13+00:00 2026-06-04T01:31:13+00:00

I try to create relationship in one entity (OneToMany in one table, parent –

  • 0

I try to create relationship in one entity (OneToMany in one table, parent – children relation) and I have a class:

public class MenuItem {
@Id
@GeneratedValue
private long Id;
private String content;
private String name;

@ManyToOne(cascade = { CascadeType.ALL })
@JoinColumn(name="parent")
private MenuItem parent;

@OneToMany(cascade = CascadeType.ALL, mappedBy="parent")
private Set<MenuItem> childrens  = new HashSet<MenuItem>();

//getters and setters

}

Loading data works good but when I try to save MenuItem, i have following error:

“Field ‘childrens_id’ doesn’t have a default value”

Hibernate tries save in MenuItem correst values (I see it in logs), but, I think, its try to create another, Join table and finnaly transaction is failed.

This is exacly shows at:
http://www.roseindia.net/hibernate/hibernate4/OnetoManySelfJoin.shtml
but not working. I used Hibernate 4.1.1 and Tomcat server 7.

Solved: Drop and create database again.

  • 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-04T01:31:15+00:00Added an answer on June 4, 2026 at 1:31 am

    guess best thing is to drop you database and run again. It seems you have hibernate/jpa impl setup to generate your database scheme, but the code and tables got too much out of synch. There is probably a field “dangling” in your table.

    As a side note: “Wild” guess: you had @JoinColumn(name="childrens_id") as a try before you changed it to the code above? (being confused with mappedBy values?)

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

Sidebar

Related Questions

I try to create a multi-threaded singleton pattern class. Header: class HL{ public: static
I have a table that stores two foreign keys, implementing a n:m relationship. One
I have a parent object which has a one to many relationship with an
I have created an ERD (Entity-Relationship Diagram) using ArgoUML and I wish to create
I have a table named UserTenders having many-to-one relationship with aspnet_Membership table. I am
I try to create unit test cases to check my table values are correct
I have two objects ( Foo and Bar ) that have a one-to-zero-or-one relationship
I am using nHibernate for db persistence. I have a one-to-many relationship defined between
I have two tables in a one to many relationship. (products and qty break
I have a master-detail relationship between 2 classes. The master class will contain a

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.