2016-11-08 3 views
0

は、私は私のエンティティを使用しようとしています、私はjdbctemplate.Iに休止/ JPAのEntityManagerから離れて移動しようとしています 例外が

@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

に以下のようなエンティティオブジェクトを持っていますCustomrowmapperの代わりにBeanPropertyRowMapperとして宣言します。

jdbcTemplate.query(SQLQueryDescriptorTest, query.toString(), parameterMap, new BeanPropertyRowMapper(MyVersion.class)); 

私は同じことに疑問を抱いています。

1)BeanPropertyRowMapperまたはCustomRowMapperを使用する場合、注釈は@NotNull @Size(max = 255)のように適用されますか?私は実体から遠ざかっています。

2)BeanPropertyRowMapperを使用している場合は、以下の例外があります。 Date

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) 

答えて

-1

変更Calendar@Temporal@DateTimeFormat注釈を削除します。