2010-11-21 16 views
0

を使用していないI次のような単純なエンティティがあります。JPAエンティティは、@Columnアノテーション

package net.plus.msodb.model; 

    import java.io.Serializable; 

    import javax.persistence.Column; 
    import javax.persistence.Entity; 
    import javax.persistence.Id; 
    import javax.persistence.Table; 

    @Entity 
    @Table(schema="msodb", name="mso") 
    public class Mso implements Serializable { 
@Id 
private Integer incidentReference; 

private String detectedDate; 
private String detectedTime; 
private String startDate; 
private String startTime; 
private String anticipatedClearDate; 
private String anticipatedClearTime; 
private String actualClearDate; 
private String actualClearTime; 
private String headline; 
private String progress; 
private String details; 
private String servicesType; 
private String servicesCount; 

public Mso() { 
} 

@Column(name="detectedDate") 
public String getDetectedDate() { 
    if(detectedDate == "") { 
    return null; 
    } 

    return detectedDate + " " + detectedTime; 
} 

     /* 
     * Getters & Setters removed to save space 
     */ 

@Column(name="detectedDate") 
public void setDetectedDate(String detectedDate) { 
    this.detectedDate = detectedDate; 
} 

public void setStartDate(String startDate) { 
    this.startDate = startDate; 
} 

public void setAnticipatedClearDate(String anticipatedClearDate) { 
    this.anticipatedClearDate = anticipatedClearDate; 
} 

public void setActualClearDate(String actualClearDate) { 
    this.actualClearDate = actualClearDate; 
} 

    } 

を、これは私が使用している設定のSmooksです:

<?xml version="1.0" encoding="UTF-8"?><smooks-resource-list xmlns="http://www.milyn.org/xsd/smooks-1.1.xsd" xmlns:jb="http://www.milyn.org/xsd/smooks/javabean-1.2.xsd"> 
    <params> 
    <param name="stream.filter.type">SAX</param> 
    <param name="inputType">input.xml</param> 
    <param name="input.xml" type="input.type.actived">Workspace://MSODBActions/src/test/resources/msos.xml</param> 
    </params> 
    <jb:bean beanId="Mso" class="net.plus.msodb.model.Mso" createOnElement="/msos/mso"> 
    <jb:value data="/msos/mso/@actualClearDate" property="actualClearDate"/> 
    <jb:value data="/msos/mso/@actualClearTime" property="actualClearTime"/> 
    <jb:value data="/msos/mso/@anticipatedClearDate" property="anticipatedClearDate"/> 
    <jb:value data="/msos/mso/@anticipatedClearTime" property="anticipatedClearTime"/> 
    <jb:value data="/msos/mso/@details" property="details"/> 
    <jb:value data="/msos/mso/@detectedDate" property="detectedDate"/> 
    <jb:value data="/msos/mso/@detectedTime" property="detectedTime"/> 
    <jb:value data="/msos/mso/@headline" property="headline"/> 
    <jb:value data="/msos/mso/@incidentReference" decoder="Integer" property="incidentReference"/> 
    <jb:value data="/msos/mso/@progress" property="progress"/> 
    <jb:value data="/msos/mso/@servicesCount" property="servicesCount"/> 
    <jb:value data="/msos/mso/@servicesType" property="servicesType"/> 
    <jb:value data="/msos/mso/@startDate" property="startDate"/> 
    <jb:value data="/msos/mso/@startTime" property="startTime"/> 
    </jb:bean> 
</smooks-resource-list> 

私がしようとすると、エンティティを保存し、次のエラーが表示されます。

Data truncation: Incorrect datetime value: '' for column 'detectedDate' at row 1 

detectedDateのゲッターから、detectedDateが空の文字列であることがわかりますその属性がSmooks変換のソースXMLにない場合)、getterはnullを返す必要があります。

コードのこの部分をデバッグすると、実際にはnullが返されます。

getterがdetectedDateの値を取得するために使用されていないのとほぼ同じです。それがnullの場合、または少なくとも1つのスペース文字列のいずれかになります。

答えて

0

私自身の質問に答えて、問題は、メンバー定義またはメソッドだけに注釈を付けることができますが、両方ではできないという事実から来ています。 @Idメンバ変数&に注釈を付けると、メソッドに他の注釈が追加されています。

@Idアノテーションをそのフィールドのゲッターに移動して問題を解決します。

関連する問題