DateTime
通过Hibernate 传递给我的插入查询时,我遇到了SQL异常。
请在尝试传递的地方找到我的Java代码DateTime
:
claimGroupingHistory.setCreatedAt(new DateTime());
claimGroupMappingRepository.insertClaimGroupingHistory(claimGroupingHistory.getDealerCode(),
claimGroupingHistory.getCreatedAt(),
claimGroupingHistory.getCreatedBy());
我收到DateTime
的格式时我SYSOUT: 2019-01-10T13:59:36.700+05:30
。
请找到我的插入查询
请找到我的例外
2019-01-10 13:59:36,754 [http-9292-1] ERROR org.hibernate.engine.jdbc.spi.SqlExceptionHelper: 146 - Data truncation: Incorrect datetime value: '\xAC\xED\x00\x05sr\x00\x16org.joda.time.DateTime\xB8<xdj[\xDD\xF9\x02\x00\x00xr\x00\x1Forg.joda.time.base.BaseDateTime\xFF\xFF\x' for column 'created_at' at row 1
2019-01-10 13:59:36,774 [http-9292-1] ERROR com.cat.pscs.api.controller.BaseController: 57 - Data Integrity Violation Exception : org.springframework.dao.DataIntegrityViolationException: could not execute statement; SQL [n/a]; nested exception is org.hibernate.exception.DataException: could not execute statement
为了帮助hibernate
持久化DateTime
到数据库,您应该在项目中使用joda-time-hibernate
而不是joda-time
。
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time-hibernate</artifactId>
<version>1.4</version>
</dependency>
修改您的实体:
@Column
@Type(type="org.joda.time.contrib.hibernate.PersistentDateTime")
private DateTime createdAt;
请注意,版本1.4适用于Hibernate 3.6。因此,joda-time-hibernate
当您使用更高级别的休眠时进行更新。
备择方案:
在中声明一个额外的依赖项pom.xml
,它可以支持的持久性joda-time
。
<dependency>
<groupId>org.jadira.usertype</groupId>
<artifactId>usertype.extended</artifactId>
<version>5.0.0.GA</version>
</dependency>
修改实体:
@Column
@Type(type="org.jadira.usertype.dateandtime.joda.PersistentLocalDate")
private DateTime createdAt;
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句