简体   繁体   English

Hibernate 中嵌入字段的默认值。 java.sql.SQLException:字段“url”没有默认值

[英]Default value for an embedded field in Hibernate. java.sql.SQLException: Field 'url' doesn't have a default value

I have an abstract class A , class B and C are subclasses of A .我有一个抽象类A ,类BCA子类。 Class B has an embedded field d . B类有一个嵌入字段d Now when I try to save an instance of B everything is fine.现在,当我尝试保存B的实例时,一切都很好。 However on creating an instance of C and saving it, I get an error :但是,在创建C实例并保存它时,出现错误:

java.sql.SQLException: Field 'string' doesn't have a default value.

Eg classes:例如类:

public abstract class  A {

}

@Embeddable
public class D {

    private String string;
}

public class B extends A{

    @Embedded
    @NotNull
    private D d;
}

public class C extends A {

}

The error you got is java.sql.Exception telling you that:你得到的错误是java.sql.Exception告诉你:

`Field 'string' doesn't have a default value.`

From the wording I assume you are using MySQL, and what the error means is, that your string field was not populated at insertion time and declared as not null.从措辞上我假设您使用的是 MySQL,并且错误的含义是,您的string字段在插入时未填充并声明为非空。 You would receive the exact same error if you were to insert a record into that table and leave the string column empty.如果您将记录插入该表并将string列留空,您将收到完全相同的错误。

What is causing your problem in the end is that you have the same table used for both classes, the string column added for the sake of object b and not populated in case of using c .最终导致您出现问题的原因是您为两个类使用了相同的表,为对象b添加的string列在使用c情况下未填充。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 java.sql.SQLException:字段没有默认值 - java.sql.SQLException: Field doesn't have a default value (Hibernate)java.sql.SQLException:字段'xxxx'没有默认值 - (Hibernate) java.sql.SQLException: Field 'xxxx' doesn't have a default value (休眠)由:java.sql.SQLException引起:字段'UPDATE_TS'没有默认值 - (Hibernate)Caused by: java.sql.SQLException: Field 'UPDATE_TS' doesn't have a default value Java 实体 java.sql.SQLException:字段“id”没有默认值 - Java Entity java.sql.SQLException: Field 'id' doesn't have a default value java.lang.RuntimeException:java.sql.SQLException:字段“ UserName”没有默认值 - java.lang.RuntimeException: java.sql.SQLException: Field 'UserName' doesn't have a default value java.sql.SQLException:字段foreign_key没有默认值 - java.sql.SQLException: Field foreign_key doesn't have a default value java.sql.SQLException: 字段 'supplier_id' 没有默认值 - java.sql.SQLException: Field 'supplier_id' doesn't have a default value Spring Boot java.sql.SQLException:字段“id”没有默认值 - Spring Boot java.sql.SQLException: Field 'id' doesn't have a default value java.sql.SQLException:字段“participant_one_fk_id”没有默认值 - java.sql.SQLException: Field 'participant_one_fk_id' doesn't have a default value 严重:java.sql.SQLException:字段'columnname'没有默认值 - Severe: java.sql.SQLException: Field 'columnname' doesn't have a default value
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM