Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/378.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 由于绑定错误,在spring数据jpa的本机查询参数中使用joda DateTime失败_Java_Jpa_Spring Data_Jodatime_Spring Data Jpa - Fatal编程技术网

Java 由于绑定错误,在spring数据jpa的本机查询参数中使用joda DateTime失败

Java 由于绑定错误,在spring数据jpa的本机查询参数中使用joda DateTime失败,java,jpa,spring-data,jodatime,spring-data-jpa,Java,Jpa,Spring Data,Jodatime,Spring Data Jpa,这里有两个查询应该完全相同,只是一个标记为本机查询,另一个标记为非本机查询。第一个可以正常工作,但第二个在转换中由于数据类型不兼容而失败 @Transactional(readOnly = true) @Query(value = "select startDate from TaskMetrics where startDate between :startDate and :endDate") List<DateTime> findStartDateByStartDa

这里有两个查询应该完全相同,只是一个标记为本机查询,另一个标记为非本机查询。第一个可以正常工作,但第二个在转换中由于数据类型不兼容而失败

  @Transactional(readOnly = true)
  @Query(value = "select startDate from TaskMetrics where startDate between :startDate and :endDate")
  List<DateTime> findStartDateByStartDateBetween(@Param("startDate") DateTime startDate,
  @Param("endDate") DateTime endDate);
带绑定

binding parameter [1] as [TIMESTAMP] - [2015-02-02 10:57:14.279]
binding parameter [2] as [TIMESTAMP] - [2015-02-04 10:57:14.281]
-

有一个绑定,这似乎也有点奇怪(特别是为什么#2?):

我使用Hibernate4.3.8.Final作为我的JPA2.1提供程序,使用JadiraUserType 3.1.0.CR10作为JodaTime支持

我是做错了什么,还是这是个错误


这里打开了一个Bug-

第二个Bug是一个
nativeQuery
,因为我知道它不能与joda DateTime一起工作。改用
Java.sql.Date

解决此错误的方法:

公共类MyDaoClass{
//joda时间用户类型库提供的转换器
private TimestampColumnDateTimeMapper columnDateTimeMapper=新的TimestampColumnDateTimeMapper();
@凌驾
公共无效doAction(MyObject MyObject){
Query q=getEntityManager().createNamedQuery(“MyNativeNamedQuery”);
q、 setParameter(“date”,columnDateTimeMapper.toNonNullValue(myObject.getDate()),TemporalType.TIMESTAMP);
q、 executeUpdate();//或选择
}

所以这是spring数据jpa中的一个错误?改用java.sql.Date对我来说不是一个可接受的解决方案。我不认为这是一个错误。不,这不是一个错误,因为您使用的是本机查询,所以jpa不知道如何映射该参数,如果您使用jpa 2+您可以做一个转换器向jpa添加新的值类型,这会产生错误吗y sense?失败的是类型的绑定。无论查询是否为本机查询,都应该正确地进行绑定。我正在使用Jadira usertype为Joda创建和注册转换器。如果不是我,第一个查询也会失败。也许问题在于Jadira。
binding parameter [1] as [TIMESTAMP] - [2015-02-02 10:57:14.279]
binding parameter [2] as [TIMESTAMP] - [2015-02-04 10:57:14.281]
  @Transactional(readOnly = true)
  @Query(nativeQuery = true, value = "select startDate from TaskMetrics where startDate between :startDate and :endDate")
  List<DateTime> findStartDateBetween(@Param("startDate") DateTime startDate,
  @Param("endDate") DateTime endDate);
select startDate from TaskMetrics where startDate between ? and ?
binding parameter [2] as [VARBINARY] - [2015-02-04T10:57:14.315-05:00]