0

所以我有一个包含映射到列的两个字段的可嵌入类型。在该类型中,两列都设置为nullable = false.

在另一个使用该可嵌入类型的对象中,我想覆盖列名并将其中一列设置为nullable = true.

@AttributeOverrides({ @AttributeOverride(name="col1", column=@Column(name="COL_1", nullable=true)), @AttributeOverride(name="col2", column=@Column(name="COL_2", nullable=false)) })

看起来不错,对吧?

当我运行我的代码时,我尝试获取 col1 为空的行,我得到了这个:

org.hibernate.PropertyAccessException: Null value was assigned to a property of primitive type setter col1

有任何想法吗?

提前致谢。

4

1 回答 1

3

The column is nullable, but the field in your entity is a primitive type (int, long, or boolean, presumably). There's no way for Hibernate to store null into a primitive type field. It should be Integer or Long or Boolean instead.

That's what the error message says: "Null value was assigned to a property of primitive type".

于 2013-07-18T13:33:24.510 回答