2016-10-28 4 views
1

私は自分のアプリケーションに春データの残りを使用しています。リストの返品方法<String>または春のスプリングデータの残り

私は自分のリポジトリで次のメソッドを使用しています。

public interface TestRepository() extends BaseRepository<TestTerm, Integer>{ 
    @Query("select distinct tt.term from TestTerm") 
     List<String> findDistinctTerm(); 
} 

私は上記の方法を実行します。私はどのように私はこの問題を解決することができ、エラー、次のSpring Data Rest (SDR) bug? Persistent Entity Must not be null

に関連

PersistentEntity must not be null 

質問を取得していますか?

このために個別の実装を記述する必要はありますか?もしそうなら誰も私のためにこれの例を教えてくれますか?

アップデート: - :

@Query("select DISTINCT term from ForbiddenTerm") 
List<TestTerm> findDistinctByTerm(); 

エラー: - -

{ "原因":ヌル、 「私はこの

方法1のように試してみました

メッセージ ":" PersistentEntityはnullであってはいけません! " }

方法2: -

List<TestTerm> findDistinctByTerm(); 

エラー: -

... 154 common frames omitted 
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.repository.support.Repositories]: Factory method 'repositories' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'forbiddenTermRepository': Invocation of init method failed; nested exception is java.util.NoSuchElementException 
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189) ~[spring-beans-4.3.3.RELEASE.jar!/:4.3.3.RELEASE] 
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588) ~[spring-beans-4.3.3.RELEASE.jar!/:4.3.3.RELEASE] 
    ... 175 common frames omitted 
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'forbiddenTermRepository': Invocation of init method failed; nested exception is java.util.NoSuchElementException 
+1

「TestTerm」タイプの登録済みエンティティのみを返すことができるため、SDRで(直接)アクセスすることはできません。このリポジトリを使用する別のコントローラを宣言する必要があります。 – kuhajeyan

+0

別途実装する必要はありません。ちなみに、あなたはSpring Bootを使っていますか? –

+0

'@Query(" TestTerm ttから別のtt.termを選択 ")'を実行するか、または:@Query( "TestTerm ttから別のttを選択") 'を実行し、' TestTerm'エンティティのリストを返し、リスト –

答えて

0

あなたはこのようなあなたのインターフェイスの名前を変更する必要があります:あなたはまた、必要

@Repository 
public interface TestTermRepository() extends BaseRepository<TestTerm, Integer>{ 
@Query("select distinct tt.term from TestTerm") 
    List<String> findDistinctTerm(); 
} 

@Repository注釈を追加する

+0

上記の方法を試しました。それは動作しません。 – karan

+0

あなたはインターフェイスの名前を変更しましたか? –

+0

はい。やった。質問 – karan

関連する問題