- 浏览: 375057 次
- 来自: 北京
文章分类
- 全部博客 (237)
- XML (6)
- JavaSE (39)
- Junit (1)
- Maven (10)
- JavaScript (12)
- JavaEE (16)
- HTML5 (10)
- java多线程 (8)
- Hibernate (30)
- Java反射 (3)
- Spring (11)
- Struts (1)
- svn (2)
- linux (12)
- 代码实例 (1)
- 设计模式 (1)
- UML (1)
- javassist (1)
- Oracle (3)
- Hibernate异常 (9)
- DWR (6)
- Java泛型 (2)
- SpringMVC (11)
- Dbunit (3)
- github (2)
- Algorithm (1)
- zTree (1)
- jquery (7)
- freemarker (4)
- mysql (5)
- ffmpeg (1)
- 编码 (1)
- lucene (15)
- hadoop (1)
- JVM (1)
- Regular Expressions (5)
- myeclipse (1)
- 爬虫 (7)
- 加密 (3)
- WebService (2)
- Socket (2)
- Windows (1)
最新评论
-
wxpsjm:
好直接
HV000030: No validator could be found for type: java.lang.Integer. -
wxhhbdx:
学习了,对新手来说很不错的教程。
SpringMVC入门 (二) 数值传递 -
xgcai:
正好在学dwr
DWR入门 (二)用户实例
org.hibernate.PropertyValueException: not-null property references a null or tra
- 博客分类:
- Hibernate异常
org.hibernate.PropertyValueException: not-null property references a null or transient value
at org.hibernate.engine.internal.Nullability.checkNullability(Nullability.java:103)
at org.hibernate.action.internal.AbstractEntityInsertAction.nullifyTransientReferencesIfNotAlready(AbstractEntityInsertAction.java:132)
at org.hibernate.action.internal.AbstractEntityInsertAction.makeEntityManaged(AbstractEntityInsertAction.java:141)
at org.hibernate.engine.spi.ActionQueue.addResolvedEntityInsertAction(ActionQueue.java:220)
at org.hibernate.engine.spi.ActionQueue.addInsertAction(ActionQueue.java:194)
at org.hibernate.engine.spi.ActionQueue.addAction(ActionQueue.java:142)
at org.hibernate.event.internal.AbstractSaveEventListener.addInsertAction(AbstractSaveEventListener.java:329)
at org.hibernate.event.internal.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:286)
at org.hibernate.event.internal.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:192)
at org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:135)
at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:206)
at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:191)
at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:114)
at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:90)
at org.hibernate.internal.SessionImpl.fireSaveOrUpdate(SessionImpl.java:735)
at org.hibernate.internal.SessionImpl.saveOrUpdate(SessionImpl.java:727)
at org.hibernate.engine.spi.CascadingAction$5.cascade(CascadingAction.java:258)
at org.hibernate.engine.internal.Cascade.cascadeToOne(Cascade.java:388)
at org.hibernate.engine.internal.Cascade.cascadeAssociation(Cascade.java:331)
at org.hibernate.engine.internal.Cascade.cascadeProperty(Cascade.java:209)
at org.hibernate.engine.internal.Cascade.cascadeCollectionElements(Cascade.java:418)
at org.hibernate.engine.internal.Cascade.cascadeCollection(Cascade.java:358)
at org.hibernate.engine.internal.Cascade.cascadeAssociation(Cascade.java:334)
at org.hibernate.engine.internal.Cascade.cascadeProperty(Cascade.java:209)
at org.hibernate.engine.internal.Cascade.cascade(Cascade.java:166)
at org.hibernate.event.internal.AbstractSaveEventListener.cascadeAfterSave(AbstractSaveEventListener.java:449)
at org.hibernate.event.internal.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:292)
at org.hibernate.event.internal.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:192)
at org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:135)
at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:206)
at org.hibernate.event.internal.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:55)
at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:191)
at org.hibernate.event.internal.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:49)
at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:90)
at org.hibernate.internal.SessionImpl.fireSave(SessionImpl.java:764)
at org.hibernate.internal.SessionImpl.save(SessionImpl.java:756)
at org.hibernate.internal.SessionImpl.save(SessionImpl.java:752)
at com.lj.zhang.Student.HibernateTeam_1insert.main(HibernateTeam_1insert.java:36)
出现这个问题的原因是没有把Student应有的IdCard加进去。
Hibernate会从我们执行session.save()中的对象开始,依次将关联的对象加进session缓存对象中。 比如这里的代码是save(team),于是会先加一个student,然后这个student对应的idcard,如此循环递归。
但是当代码运行到Student的循环时,根据映射配置文件, 该student应该对应一个idcard,且不能为null,于是就报错了。
如下图所示,当加入了代码:
values[1]那里便有了该有的idcard对象地址。
之前那里为null,抛出异常。
at org.hibernate.engine.internal.Nullability.checkNullability(Nullability.java:103)
at org.hibernate.action.internal.AbstractEntityInsertAction.nullifyTransientReferencesIfNotAlready(AbstractEntityInsertAction.java:132)
at org.hibernate.action.internal.AbstractEntityInsertAction.makeEntityManaged(AbstractEntityInsertAction.java:141)
at org.hibernate.engine.spi.ActionQueue.addResolvedEntityInsertAction(ActionQueue.java:220)
at org.hibernate.engine.spi.ActionQueue.addInsertAction(ActionQueue.java:194)
at org.hibernate.engine.spi.ActionQueue.addAction(ActionQueue.java:142)
at org.hibernate.event.internal.AbstractSaveEventListener.addInsertAction(AbstractSaveEventListener.java:329)
at org.hibernate.event.internal.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:286)
at org.hibernate.event.internal.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:192)
at org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:135)
at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:206)
at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:191)
at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:114)
at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:90)
at org.hibernate.internal.SessionImpl.fireSaveOrUpdate(SessionImpl.java:735)
at org.hibernate.internal.SessionImpl.saveOrUpdate(SessionImpl.java:727)
at org.hibernate.engine.spi.CascadingAction$5.cascade(CascadingAction.java:258)
at org.hibernate.engine.internal.Cascade.cascadeToOne(Cascade.java:388)
at org.hibernate.engine.internal.Cascade.cascadeAssociation(Cascade.java:331)
at org.hibernate.engine.internal.Cascade.cascadeProperty(Cascade.java:209)
at org.hibernate.engine.internal.Cascade.cascadeCollectionElements(Cascade.java:418)
at org.hibernate.engine.internal.Cascade.cascadeCollection(Cascade.java:358)
at org.hibernate.engine.internal.Cascade.cascadeAssociation(Cascade.java:334)
at org.hibernate.engine.internal.Cascade.cascadeProperty(Cascade.java:209)
at org.hibernate.engine.internal.Cascade.cascade(Cascade.java:166)
at org.hibernate.event.internal.AbstractSaveEventListener.cascadeAfterSave(AbstractSaveEventListener.java:449)
at org.hibernate.event.internal.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:292)
at org.hibernate.event.internal.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:192)
at org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:135)
at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:206)
at org.hibernate.event.internal.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:55)
at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:191)
at org.hibernate.event.internal.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:49)
at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:90)
at org.hibernate.internal.SessionImpl.fireSave(SessionImpl.java:764)
at org.hibernate.internal.SessionImpl.save(SessionImpl.java:756)
at org.hibernate.internal.SessionImpl.save(SessionImpl.java:752)
at com.lj.zhang.Student.HibernateTeam_1insert.main(HibernateTeam_1insert.java:36)
Session session=HibernateUtil.openSession(); Team team=new Team(null,"impl_team",null); Student s1=new Student("alleni", null); Student s2=new Student("eline",null); IdCard card1=new IdCard(001, s1); IdCard card2=new IdCard(002,s2); team.setStudents(ArraysHelper.asSet(s1,s2)); Transaction tx=session.beginTransaction(); session.save(team); tx.commit();
package org.hibernate.engine.internal public final class Nullability /** Check nullability of the class persister properties /* @param values entity properties public void checkNullability { ... //这里会对所有transient状态的对象进行检查,没有异常则进入下一步,最终持久化。 for ( int i = 0; i < values.length; i++ ) { if ( checkability[i] && values[i]!= LazyPropertyInitializer.UNFETCHED_PROPERTY ) { final Object value = values[i]; if ( !nullability[i] && value == null ) { //check basic level one nullablilty throw new PropertyValueException( "not-null property references a null or transient value", persister.getEntityName(), persister.getPropertyNames()[i] ); } else if ( value != null ) { //values is not null and is checkable, we'll look deeper String breakProperties = checkSubElementsNullability( propertyTypes[i], value ); if ( breakProperties != null ) { throw new PropertyValueException( "not-null property references a null or transient value", persister.getEntityName(), buildPropertyPath( persister.getPropertyNames()[i], breakProperties ) ); } } } ... }
出现这个问题的原因是没有把Student应有的IdCard加进去。
Hibernate会从我们执行session.save()中的对象开始,依次将关联的对象加进session缓存对象中。 比如这里的代码是save(team),于是会先加一个student,然后这个student对应的idcard,如此循环递归。
但是当代码运行到Student的循环时,根据映射配置文件, 该student应该对应一个idcard,且不能为null,于是就报错了。
如下图所示,当加入了代码:
s1.setIdCard(card1); s2.setIdCard(card2);
values[1]那里便有了该有的idcard对象地址。
之前那里为null,抛出异常。
发表评论
-
Hibernate连接Mysql的8小时问题
2014-05-03 13:06 1217这个问题估计是用mysql建立网站都会碰到的。 每天早上起来打 ... -
Unable to locate appropriate constructor on class
2014-02-20 00:11 1457org.hibernate.hql.internal.ast. ... -
org.hibernate.exception.SQLGrammarException: could not extract ResultSet
2014-01-21 21:25 8257今天是SQL语句写错。 String type String ... -
use either Oracle9iDialect or Oracle10gDialect instead
2013-12-16 10:40 203210:30:16,909 WARN Oracle9Diale ... -
Hibernate关闭show_sql功能的一点问题
2013-12-12 13:08 18由于hibernate开启了show_sql,会产生大量的sq ... -
Error creating bean with name 'userDao'
2013-12-10 20:19 3315严重: Context initialization ... -
org.hibernate.MappingException: Association references unmapped class:
2013-11-25 15:41 1197INFO: HHH000424: Disabling cont ... -
Could not get constructor for org.hibernate.persister.entity.SingleTableEntityPe
2013-11-23 17:17 7114Caused by: org.hibernate.Mappin ... -
<Hibernate笔记> 配置文件属性设置
2013-11-21 15:57 649<many-to-one not-null='true' ...
相关推荐
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/...
Then add/update references to Dart.Snmp.Dll in your project. No limits, no nagging messages. Enjoy. And if you like the product, then buy it. Support the software companies and developers!
- 表示数据库中的NULL值,在.NET框架中用于区分普通语言中的null。 18. **Profile**: - 配置文件。 - 通常包含特定于用户或应用程序的设置。 19. **Constraint**: - 约束。 - 数据库中用于确保数据完整性的...
Not-null property references a null or transient value 当Hibernate尝试保存一个实体时,如果该实体中的某个被标记为`@NotNull`或在映射文件中定义为`not-null="true"`的属性值为null或者指向一个尚未持久化的...
在描述中提到的`org.hibernate.PropertyValueException: not-null property references a null or transient value`是Hibernate抛出的一个常见异常,表示尝试保存一个实体时,其某个非空属性为null或未持久化。...
在Java世界中,Java Persistence API(JPA)是Oracle公司推出的用于对象关系映射(ORM)的标准框架,它简化了数据库操作,使开发者能够用Java对象来操作数据库记录。本教程将深入探讨JPA中的一对多双向关联及级联...
org.hibernate.PropertyValueException: not-null property references a null or transient value 当你尝试保存一个实体时,如果该实体中某个被标记为`@NotNull`或`@Column(nullable = false)`的属性值为null,则...
Version V6.48 (2019-07-26) Added flash programming support for AmbiqMicro's AMA2B1KK ...Firmware: J-Link EDU Mini: RISC-V: On implementations that do not populate a "program buffer" CSRs could not ...
10.1038_d41586-022-00985-9-references.ris (1)
10.1007_s11704-022-1389-x-references (2).ris
--level-idc |float> Force a minumum required decoder level (as '5.0' or '50') --[no-]high-tier If a decoder level is specified, this modifier selects High tier of that level Threading, performance:...
- **说明**:表示尝试为允许NULL的列设置NOT NULL约束。 45. **+65001538** - **SQLSTATE**: 538 - **说明**:表示索引的锁状态被非法更改。 46. **+65301551** - **SQLSTATE**: 551 - **说明**:表示指定...
**标题:“Hibernate Annotations”** **概述** Hibernate是一个流行的Java对象关系映射(ORM)框架,它简化了在Java应用程序中处理数据库的过程。Hibernate Annotations是Hibernate框架的一个重要组成部分,它...
REFERENCES GOUGH, H., (1975). Manual for the California Psychological Inventory. Palo Alto, CA: Consulting GOUGH, H. (1987). Administrator’s guidefor the California Psychological Inventory. Palo ...
**PropertyValueException: not-null property references a null or transient value** **异常描述:** 此异常表明一个标记为不可为空的属性引用了一个null或瞬态值。 **解决方法:** - 确认所有标有`not-null`...
% -----References:----- % Hill, I. D. 1976. Algorithm AS 100: Normal-Johnson and Johnson-Normal % Transformations. Journal of the Royal Statistical Society. Series C (Applied % Statistics) 25(2): 190-...
- **描述**: 在尝试向不允许NULL值的列插入NULL值时出现问题。 ##### 45. 锁定失败 - **SQLCODE**: +65001 - **SQLSTATE**: 538 - **描述**: 尝试锁定某行数据时失败。 ##### 46. 缓冲池问题 - **SQLCODE**: +...
E.g.: if (DragDetectPlus(THandle(MyControl->Handle), Point(X, Y))) { ... } * Virtual File Stream formats can only be pasted from the clipboard with live data (i.e. FlushClipboard/...
Benefits of reading this book that you’re not going to find anywhere else: Introduction to Machine Learning Classification How to train a Model Different Models Combinations CHAPTER1 INTRODUCTION TO ...
CMake is a cross-platform, open-source build system generator. For full documentation visit the CMake Home Page and the CMake Documentation Page. The CMake Community Wiki also references useful guides...