2017-07-28 9 views
0

私はいくつかのカスタム機能をSpringデータリポジトリに追加しようとしています。 私は、次のコードを作成している私の出発点http://docs.spring.io/spring-data/jpa/docs/current/reference/html/#repositories.single-repository-behaviourとしてこれを使用する:Springリポジトリのカスタムメソッド

public interface TableLock<T> { 
    void checkout(T entity); 
    void checkin(T entity, boolean cmpltBatch); 
} 


public interface BatchTableLock extends TableLock<MyEntity> { 

} 

public class BatchTableLockImpl implements BatchTableLock { 
    private static final Logger logger = LoggerFactory.getLogger(BatchTableLockImpl.class); 
    @PersistenceContext(unitName = "mysql") 
    private EntityManager em; 

    @Override 
    public void checkout(MyEntity batch) { 
    Long id = batch.getMyEntityId(); 
    try { 
     MyEntity p = em.find(MyEntity.class, id, LockModeType.PESSIMISTIC_WRITE); 
     if (p == null) { 
      logger.error("checkout : MyEntity id {} must be valid", id); 
      throw new PessimisticLockException(); 
     } 
     if (myCondition is true) { 
      return; 
     } 
    } catch (LockTimeoutException | PessimisticLockException e) { 
     logger.error("checkout : Unable to get write lock on MyEntity id {}", id, e); 
    } 
    throw new PessimisticLockException(); 
} 

@Override 
public void checkin(MyEntity batch, boolean cmplt) { 
    Long id = batch.getMyEntityId(); 
    try { 
     MyEntity p = em.find(MyEntity.class, id, LockModeType.PESSIMISTIC_WRITE); 
     if (p == null) { 
      logger.error("complete : MyEntity id {} must be valid", id); 
      return; 
     } 
     if (this is true) { 
      if (cmplt) { 
       yep; 
      } else { 
       nope; 
      } 
     } else if (cmplt) { 
      logger.error("complete: Unable to complete MyEntity {} with status.", id); 
     } 
    } catch (LockTimeoutException | PessimisticLockException e) { 
     logger.error("complete : Unable to get write lock on MyEntity id {}", id, e); 
    } 
} 

} 

@Repository 
public interface MyDao extends CrudRepository<MyEntity, BigInteger>, BatchTableLock { 
    ... My queries ... 
} 

、残念ながら私は、次のようなエラーになっています:

org.springframework.data.mapping.PropertyReferenceException: No property checkin found for type MyEntity! 

これを私は間違っていない場合は、スプリングをしようとしていることを意味メソッド 'checkin'に基づいてクエリを生成し、MyEntity内で 'checkin'という名前のフィールドを見つけることができません。そのようなフィールドはありません。これをやめさせるにはどうすればいいですか?上記のリンクに基づいて、私はこのメソッドのクエリを生成しようとしているはずはないと思っていますが、とにかくそれをやっているようです。私は何かが欠けているかもしれませんが、それは通常そうですが、私はそれが何かを見ません。

答えて

2

リンク先の参照ドキュメントセクションに記載されているように、カスタムメソッドを実装するMyDaoImplクラスが必要です。私は最も簡単な方法はBatchTableLockImplの名前を変更するか、そのクラスを拡張する空のMyDaoImplを作成することだと思います。

+0

ありがとうオリバーは、ドキュメントの混乱と私の誤解をおかけして申し訳ありません。 – peekay

関連する問題