错误如下:
Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.orm.jpa.JpaSystemException: Null value was assigned to a property [class com.liu.pojo.Student.stuAge] of primitive type setter of com.liu.pojo.Student.stuAge; nested exception is org.hibernate.PropertyAccessException: Null value was assigned to a property [class com.liu.pojo.Student.stuAge] of primitive type setter of com.liu.pojo.Student.stuAge] with root cause
java.lang.IllegalArgumentException: Can not set int field com.liu.pojo.Student.stuAge to null value
at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:167) ~[na:1.8.0_151]
at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:171) ~[na:1.8.0_151]
at sun.reflect.UnsafeIntegerFieldAccessorImpl.set(UnsafeIntegerFieldAccessorImpl.java:80) ~[na:1.8.0_151]
at java.lang.reflect.Field.set(Field.java:764) ~[na:1.8.0_151]
at org.hibernate.property.access.spi.SetterFieldImpl.set(SetterFieldImpl.java:52) ~[hibernate-core-5.4.18.Final.jar:5.4.18.Final]
at org.hibernate.tuple.entity.AbstractEntityTuplizer.setPropertyValues(AbstractEntityTuplizer.java:680) ~[hibernate-core-5.4.18.Final.jar:5.4.18.Final]
at org.hibernate.tuple.entity.PojoEntityTuplizer.setPropertyValues(PojoEntityTuplizer.java:144) ~[hibernate-core-5.4.18.Final.jar:5.4.18.Final]
at org.hibernate.persister.entity.AbstractEntityPersister.setPropertyValues(AbstractEntityPersister.java:5119) ~[hibernate-core-5.4.18.Final.jar:5.4.18.Final]
at org.hibernate.engine.internal.TwoPhaseLoad.initializeEntityFromEntityEntryLoadedState(TwoPhaseLoad.java:290) ~[hibernate-core-5.4.18.Final.jar:5.4.18.Final]
at org.hibernate.engine.internal.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:185) ~[hibernate-core-5.4.18.Final.jar:5.4.18.Final]
at org.hibernate.engine.internal.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:153) ~[hibernate-core-5.4.18.Final.jar:5.4.18.Final]
at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:1203) ~[hibernate-core-5.4.18.Final.jar:5.4.18.Final]
at org.hibernate.loader.Loader.processResultSet(Loader.java:1004) ~[hibernate-core-5.4.18.Final.jar:5.4.18.Final]
at org.hibernate.loader.Loader.doQuery(Loader.java:962) ~[hibernate-core-5.4.18.Final.jar:5.4.18.Final]
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:352) ~[hibernate-core-5.4.18.Final.jar:5.4.18.Final]
at org.hibernate.loader.Loader.doList(Loader.java:2857) ~[hibernate-core-5.4.18.Final.jar:5.4.18.Final]
at org.hibernate.loader.Loader.doList(Loader.java:2839) ~[hibernate-core-5.4.18.Final.jar:5.4.18.Final]
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2671) ~[hibernate-core-5.4.18.Final.jar:5.4.18.Final]
at org.hibernate.loader.Loader.list(Loader.java:2666) ~[hibernate-core-5.4.18.Final.jar:5.4.18.Final]
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:506) ~[hibernate-core-5.4.18.Final.jar:5.4.18.Final]
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:400) ~[hibernate-core-5.4.18.Final.jar:5.4.18.Final]
at org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:219) ~[hibernate-core-5.4.18.Final.jar:5.4.18.Final]
at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1412) ~[hibernate-core-5.4.18.Final.jar:5.4.18.Final]
at org.hibernate.query.internal.AbstractProducedQuery.doList(AbstractProducedQuery.java:1565) ~[hibernate-core-5.4.18.Final.jar:5.4.18.Final]
at org.hibernate.query.internal.AbstractProducedQuery.list(AbstractProducedQuery.java:1533) ~[hibernate-core-5.4.18.Final.jar:5.4.18.Final]
at org.hibernate.query.Query.getResultList(Query.java:165) ~[hibernate-core-5.4.18.Final.jar:5.4.18.Final]
at org.springframework.data.jpa.repository.query.JpaQueryExecution$CollectionExecution.doExecute(JpaQueryExecution.java:126) ~[spring-data-jpa-2.3.2.RELEASE.jar:2.3.2.RELEASE]
at org.springframework.data.jpa.repository.query.JpaQueryExecution.execute(JpaQueryExecution.java:88) ~[spring-data-jpa-2.3.2.RELEASE.jar:2.3.2.RELEASE]
at org.springframework.data.jpa.repository.query.AbstractJpaQuery.doExecute(AbstractJpaQuery.java:154) ~[spring-data-jpa-2.3.2.RELEASE.jar:2.3.2.RELEASE]
at org.springframework.data.jpa.repository.query.AbstractJpaQuery.execute(AbstractJpaQuery.java:142) ~[spring-data-jpa-2.3.2.RELEASE.jar:2.3.2.RELEASE]
at org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor$QueryMethodInvoker.invoke(QueryExecutorMethodInterceptor.java:195) ~[spring-data-commons-2.3.2.RELEASE.jar:2.3.2.RELEASE]
at org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor.doInvoke(QueryExecutorMethodInterceptor.java:152) ~[spring-data-commons-2.3.2.RELEASE.jar:2.3.2.RELEASE]
at org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor.invoke(QueryExecutorMethodInterceptor.java:130) ~[spring-data-commons-2.3.2.RELEASE.jar:2.3.2.RELEASE]
at
造成原因
数据库中表字段对应的数据与该字段的数据类型不一致导致的,比如表字段的数据类型为Int,而数据为NULL,Int类型不能赋值为NULL,就是这样子数据类型不一致才会导致这个错误
解决问题
- 数据库给值,或者为空的话默认给个符合条件的值
- 重新刷新,问题解决