异常而映射实体排在Spring的JdbcTemplate映射
问题描述:
我有一个实体对象如下面的JPA异常而映射实体排在Spring的JdbcTemplate映射
@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
}
我试图从休眠/ JPA的EntityManager到jdbctemplate.I移开我试图用我的实体作为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)
答
更改Calendar
到Date
并删除@Temporal
和@DateTimeFormat
注解。