The problem of hibernate one-way one-to-many should be noticed

Source: Internet
Author: User
Tags set set sql error

The question bothered me for more than 10 days and finally got rid of it.

I use Myeclipse6.5ga to hibernate a one-to-many one-way correlation instance.

Always reported the following exception:

Hibernate:
Insert
Into
Hbql.score
(Score, type)
Values
。。。。。。。。。。。。。。。。。。。
17:03:32,484 DEBUG jdbcexceptionreporter:69-could not insert: [Score. Score] [insert INTO Hbql.score (Score, type) VALUES (?,?)]
Java.sql.SQLException:Field ' sid ' doesn ' t have a default value
At Com.mysql.jdbc.SQLError.createSQLException (sqlerror.java:1055)
..../long hair is not good.//* * * Omit point
17:03:32,484 WARN jdbcexceptionreporter:77-sql error:1364, sqlstate:hy000
17:03:32,484 ERROR jdbcexceptionreporter:78-field ' sid ' doesn ' t have a default value
Save object Student. Student failed!
17:03:32,484 DEBUG Jdbctransaction:152-rollback
Org.hibernate.exception.GenericJDBCException:could not insert: [Score. Score]
At Org.hibernate.exception.SQLStateConverter.handledNonSpecificException (sqlstateconverter.java:103)
At Org.hibernate.exception.SQLStateConverter.convert (sqlstateconverter.java:91)
.....//too long hair is not good.///Too much of a lot. Omit point
caused By:java.sql.SQLException:Field ' sid ' doesn ' t have a default value
At Com.mysql.jdbc.SQLError.createSQLException (sqlerror.java:1055)

The test procedure is as follows:

Student student=new Student("huizhi","2708",200);
Score score1=new Score(98,"1");
Score score2=new Score(90,"2");
Set set=new HashSet();
set.add(score1);
set.add(score2);
student.setScores(set);
saveObject(student);
printStudents();
----------------------------------------------------------------------------------------------------------------------

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.