Java Spring存储库自定义方法

Java Spring存储库自定义方法,java,spring,repository,spring-data-jpa,Java,Spring,Repository,Spring Data Jpa,我正在尝试向spring数据存储库添加一些自定义功能。 以此为起点,我创建了以下代码: public interface TableLock<T> { void checkout(T entity); void checkin(T entity, boolean cmpltBatch); } public interface BatchTableLock extends TableLock<MyEntity> { } public class Ba

我正在尝试向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 ...
}

如果我没有弄错的话,这意味着spring正试图基于“checkin”方法生成一个查询,但在MyEntity中找不到名为“checkin”的字段。这是正确的,没有这样的字段。我如何让它停止这样做?基于上面的链接,我不认为它应该尝试为这个方法生成一个查询,但它似乎无论如何都在这样做。通常情况下,我可能遗漏了一些东西,但我看不出是什么。

如您链接到的参考文档部分所述,您需要一个实现自定义方法的
MyDaoImpl
类。我想最简单的方法是将
BatchTableLockImpl
重命名为该类,或者只是创建一个空的
MyDaoImpl
扩展该类。

感谢Oliver,很抱歉我对文档的混淆和误解。
org.springframework.data.mapping.PropertyReferenceException: No property checkin found for type MyEntity!