2017-02-28 11 views
0

私の頭をデバッグした後、私はアイデアがなくなり、助けが必要になります。実際に私がひどく興味をそそられていることは、私がやろうとしていることの単純さとそれを達成することが不可能なことです。 私は春休みデータの小さなデモを作成しようとしています。それらをメモリ内のh2データベースに保存します。Springデータの残り - サブクラス化するとリソースが利用できなくなる

次のコードは動作します:

@Entity 
@Table(name="info") 
@Inheritance(strategy = InheritanceType.SINGLE_TABLE) 
@DiscriminatorColumn(name="INFO_TYPE", discriminatorType=DiscriminatorType.STRING) 
public class ItemInfo { 
    @Id 
    @GeneratedValue(strategy = GenerationType.AUTO) 
    @Column(name = "id") 
    public long id; 
    public long getId() { 
     return id; 
    } 
    public void setId(long id) { 
     this.id = id; 
    } 
} 
@RepositoryRestResource(collectionResourceRel="itemInfos", path="itemInfos") 
public interface ItemInfoRepository extends PagingAndSortingRepository<ItemInfo, Long> { 

} 

私はカールhttp://localhost:8080/itemInfos用カール要求を発行すると、私は次のように正しい応答を得る:できるだけ早く私はのサブクラスのエンティティを追加すると、しかし

{ 
    "_embedded" : { 
    "itemInfos" : [ ] 
    }, 
    "_links" : { 
    "self" : { 
     "href" : "http://localhost:8080/itemInfos" 
    }, 
    "profile" : { 
     "href" : "http://localhost:8080/profile/itemInfos" 
    } 
    }, 
    "page" : { 
    "size" : 20, 
    "totalElements" : 0, 
    "totalPages" : 0, 
    "number" : 0 
    } 
} 

をItemInfo、/ itemInfosリソースはもう使用できなくなります。

だから、クラスを追加:以前は、エラーを生成するよう

@Entity 
@Table(name="info") 
@DiscriminatorValue(value="COMMENT") 
public class UserComment extends ItemInfo { 
    private String from; 
    private String comment; 

    public String getFrom() { 
     return from; 
    } 

    public void setFrom(String from) { 
     this.from = from; 
    } 

    public String getComment() { 
     return comment; 
    } 

    public void setComment(String comment) { 
     this.comment = comment; 
    } 
} 

は同じcurlコマンドになります:

{"timestamp":1488282548770,"status":500,"error":"Internal Server Error","exception":"org.springframework.dao.InvalidDataAccessResourceUsageException","message":"could not prepare statement; SQL [select iteminfo0_.id as id2_0_, iteminfo0_.comment as comment3_0_, iteminfo0_.from as from4_0_, iteminfo0_.info_type as info_typ1_0_ from info iteminfo0_ limit ?]; nested exception is org.hibernate.exception.SQLGrammarException: could not prepare statement","path":"/itemInfos"} 

はさらに、新しいitemInfoを追加しようとすると、同様のエラーが発生します。

{"timestamp":1488282718547,"status":500,"error":"Internal Server Error","exception":"org.springframework.dao.InvalidDataAccessResourceUsageException","message":"could not prepare statement; SQL [insert into info (id, info_type) values (null, 'ItemInfo')]; nested exception is org.hibernate.exception.SQLGrammarException: could not prepare statement","path":"/itemInfos"} 

UserCommentRepositoryを追加しても、問題は解決されません。

curl -i -X POST -H "Content-Type:application/json" -d "{ \"from\" : \"Ana\", \"comment\" : \"some comment\" }" http://localhost:8080/userComments 

が、私はさらにエラーを取得する:私は、新しいユーザーのコメントを追加しようとした場合この場合
public interface UserCommentRepository extends PagingAndSortingRepository<UserComment, Long> { } 
は、

{"timestamp":1488282968879,"status":500,"error":"Internal Server Error","exception":"org.springframework.dao.InvalidDataAccessResourceUsageException","message":"could not prepare statement; SQL [insert into info (id, comment, from, info_type) values (null, ?, ?, 'COMMENT')]; nested exception is org.hibernate.exception.SQLGrammarException: could not prepare statement","path":"/userComments"} 

完全に私のエンティティの継承を追加するようです私の資源を滅ぼす。あなたの誰かが似たような問題を抱えていましたか?

答えて

0

オクラホマ...私はそれを(主に間違えて)考え出し、それはさらにイライラします。 問題は変数名 "from"の使用でした。これは、春のデータ休憩はキーワードとしてこれを使用するようです。この変数の名前をリファクタリングすると、すべてが期待通りに機能しました。残念ながら、例外とエラーメッセージはまったく役に立たなかった。 うまくいけば、他の人が同じデバッグ地獄を通過しないでしょう...

関連する問題