Java 在spring jdbctemplate中将实体映射到行映射器时发生异常
我在JPA中有一个如下所示的实体对象Java 在spring jdbctemplate中将实体映射到行映射器时发生异常,java,spring,Java,Spring,我在JPA中有一个如下所示的实体对象 @Entity @Table(name="my_version") public class MyVersion implements EntityKeyOverride { @Id @GeneratedValue(strategy = GenerationType.AUTO) @Column(name = "id") private Long id; @NotNull private Long instan
@Entity
@Table(name="my_version")
public class MyVersion implements EntityKeyOverride {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id")
private Long id;
@NotNull
private Long instanceId;
@NotNull
private Long documentId;
@NotNull
@Size(max = 255)
private String name;
@NotNull
private Integer majorVersion;
@NotNull
private Integer minorVersion;
@Size(max = 255)
private String classification;
@Size(max = 1500)
private String description;
@Size(max = 1500)
private String title;
@Size(max = 255)
private String lifecycle;
@NotNull
@Temporal(TemporalType.TIMESTAMP)
@DateTimeFormat(style = "LL", iso = ISO.DATE_TIME)
private Calendar createdDate;
//getter and setter
}
我正在尝试从hibernate/jpa entitymanager转移到jdbctemplate。我正在尝试将我的实体用作BeanPropertyRowMapper,而不是Customrowmapper
jdbcTemplate.query(SQLQueryDescriptorTest, query.toString(), parameterMap, new BeanPropertyRowMapper(MyVersion.class));
对于这一点,我几乎没有什么疑问
1) 如果我使用BeanPropertyRowMapper或CustomRowMapper,注释会像@NotNull@Size(max=255)
一样应用吗?因为我正在远离实体
2) 当使用BeanPropertyRowMapper时,我得到以下异常
caused by: org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type [java.sql.Timestamp] to required type [java.util.Calendar] for property 'createdDate'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.sql.Timestamp] to required type [java.util.Calendar] for property 'createdDate': no matching editors or conversion strategy found
at org.springframework.beans.AbstractNestablePropertyAccessor.convertIfNecessary(AbstractNestablePropertyAccessor.java:591)
at org.springframework.beans.AbstractNestablePropertyAccessor.convertForProperty(AbstractNestablePropertyAccessor.java:603)
at org.springframework.beans.AbstractNestablePropertyAccessor.setPropertyValue(AbstractNestablePropertyAccessor.java:449)
将
日历
更改为日期
,并删除@Temporal
和@DateTimeFormat
注释