我在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 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)
答案 0 :(得分:-2)
将Calendar
更改为Date
并删除@Temporal
和@DateTimeFormat
注释。