错误:org.hibernate.PropertyValueException: not-null property references a null
2014-03-24 23:52
453 查看
电脑表和员工表配置了多对一的关系,配置如下
@ManyToOne(cascade=CascadeType.ALL,fetch=FetchType.EAGER,optional=false)
public EmployeeEntity getEmployeeEntity() {
return employeeEntity;
}
奇怪的是我删除电脑表一条记录,老是报错,我就纳闷了 在电脑表里面维护了关键,有一个外键,参照了员工表中的员工编号,如图所示
补补小知识吧,你看,电脑表里面,维护了电脑表和员工表的关系,电脑表里面有一个外键,也就是所谓的参照键,它参考了员工表中的员工编号
情况就是这么个情况,随便网上查了查,我觉得外键可不可以为空,看你设置可以不可以就OK了
话说回来,为啥子酒保这个错误的,于是找啊找,看到这位大哥的帖子了,连接http://www.cnblogs.com/yezhenhan/archive/2011/10/20/2218883.html
optional属性是定义该关联类是否必须存在,值为false 时,关联类双方都必须存在,如果关系被维护端不存在,查询的结果为null。值为true 时, 关系被维护端可以不存在,查询的结果仍然会返回关系维护端,在关系维护端中指向关系被维护端的属性为null。optional属性的默认值是true。optional
属性实际上指定关联类与被关联类的join 查询关系,如optional=false
时join 查询关系为inner join, optional=true 时join 查询关系为left join。下面代码片断解释如下
正是因为这个原因,我们必须让维护关系放可以是可选的才行,否则就会出现标题中的错误
@ManyToOne(cascade=CascadeType.ALL,fetch=FetchType.EAGER,optional=false)
public EmployeeEntity getEmployeeEntity() {
return employeeEntity;
}
奇怪的是我删除电脑表一条记录,老是报错,我就纳闷了 在电脑表里面维护了关键,有一个外键,参照了员工表中的员工编号,如图所示
补补小知识吧,你看,电脑表里面,维护了电脑表和员工表的关系,电脑表里面有一个外键,也就是所谓的参照键,它参考了员工表中的员工编号
情况就是这么个情况,随便网上查了查,我觉得外键可不可以为空,看你设置可以不可以就OK了
话说回来,为啥子酒保这个错误的,于是找啊找,看到这位大哥的帖子了,连接http://www.cnblogs.com/yezhenhan/archive/2011/10/20/2218883.html
optional属性是定义该关联类是否必须存在,值为false 时,关联类双方都必须存在,如果关系被维护端不存在,查询的结果为null。值为true 时, 关系被维护端可以不存在,查询的结果仍然会返回关系维护端,在关系维护端中指向关系被维护端的属性为null。optional属性的默认值是true。optional
属性实际上指定关联类与被关联类的join 查询关系,如optional=false
时join 查询关系为inner join, optional=true 时join 查询关系为left join。下面代码片断解释如下
正是因为这个原因,我们必须让维护关系放可以是可选的才行,否则就会出现标题中的错误
相关文章推荐
- 错误:org.hibernate.PropertyValueException:not-null property references a null or transient value
- org.hibernate.PropertyValueException: not-null property references a null or transient value : xxx
- org.hibernate.PropertyValueException: not-null property references a null or transient value
- org.hibernate.PropertyValueException: not-null property references a null or transient value
- org.hibernate.PropertyValueException: not-null property references a null or transient value
- org.hibernate.PropertyValueException: not-null property references a null or transient value:
- Caused by: org.hibernate.PropertyValueException: not-null property references a null or transient va
- org.hibernate.PropertyValueException: not-null property references a null or transient value: model.
- org.hibernate.PropertyValueException: not-null property references a null or transient value: model.
- org.hibernate.PropertyAccessException: Null value was assigned to a property of primitive type setter of com.xugao.bean.MemberLevel.memberpointrate
- hibernate异常:not-null property references a null or transient value
- org.hibernate.AnnotationException: Referenced property not a (One|Many)ToOne: in mappedBy of
- nested exception is org.hibernate.PropertyAccessException: Null value was assigned to a property of
- org.hibernate.PropertyAccessException: Null value was assigned to a property of primitive type sette
- org.hibernate.PropertyAccessException: Null value was assigned to a property of primitive type sette
- not-null property references a null or transient value : org.com.model.person_one_one_test.address
- Hibernate错误 Caused by: org.hibernate.PropertyNotFoundException: Could not find a getter for pnsame i
- org.hibernate.PropertyAccessException: Null value was assigned to a property of primitive type setter of com.chen.vo.Dept.parentId
- 关于hibernate(jpa)报not-null property references a null or transient value的问题
- 常见Hibernate报错处理:出现“org.hibernate.QueryException: could not resolve property”和 is not mapped和could not locate named parameter错误的解决