【Could not read entity state from ResultSet】解决报错

org.springframework.dao.DataIntegrityViolationException: Could not read entity state from ResultSet : EntityKey[com.ledar.mono.domain.User#2]; SQL [n/a]; nested exception is org.hibernate.exception.DataException: Could not read entity state from ResultSet : EntityKey[com.ledar.mono.domain.User#2]
	at org.springframework.orm.jpa.vendor.HibernateJpaDialect.convertHibernateAccessException(HibernateJpaDialect.java:280)
	at org.springframework.orm.jpa.vendor.HibernateJpaDialect.translateExceptionIfPossible(HibernateJpaDialect.java:233)
	at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.translateExceptionIfPossible(AbstractEntityManagerFactoryBean.java:551)
	at org.springframework.dao.support.ChainedPersistenceExceptionTranslator.translateExceptionIfPossible(ChainedPersistenceExceptionTranslator.java:61)
	at org.springframework.dao.support.DataAccessUtils.translateIfNecessary(DataAccessUtils.java:242)
	at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:152)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
	at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodInterceptor.invoke(CrudMethodMetadataPostProcessor.java:174)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
	at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:97)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)

Caused by: java.sql.SQLDataException: Cannot determine value type from string 'NORMAL'
	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:114)
	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)
	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:89)
	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:63)
	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:73)
	at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:96)
	at com.mysql.cj.jdbc.result.ResultSetImpl.getObject(ResultSetImpl.java:1431)
	at com.mysql.cj.jdbc.result.ResultSetImpl.getInt(ResultSetImpl.java:830)
	at com.mysql.cj.jdbc.result.ResultSetImpl.getInt(ResultSetImpl.java:851)

解决方法:实际上,Could not read entity state from ResultSet : EntityKey[com.ledar.mono.domain.User#2];,这段话大意是,你的实体类的某个字段属性和数据库表中的字段属性不一致。
你需要检查这个类和相应的数据库。
检查后发现:
注意看user_status字段类型是varchar
在这里插入图片描述
相应的实体类的对应属性是Status userStatus Status类型是自定义的一个Enumeration类型。运行项目后实体类会自动注入到数据库,自动生成的类型也是varchar,为啥会报错,百思不得解。直到看见。报错解决方法
在这里插入图片描述
原来,我忘记加 @Enumerated(EnumType.STRING)这条语句了。使得实体类和数据库表类型userStatus类型不一致。
加上之后的类属性:
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_45486709/article/details/123455342
今日推荐