1

I am trying to add some custom functionality to a spring data repository. Using this as my starting point http://docs.spring.io/spring-data/jpa/docs/current/reference/html/#repositories.single-repository-behaviour I have created the following code:

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 ...
}

unfortunately I am getting the following error:

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

This if I'm not mistaken means that spring is trying to generate a query based on the method 'checkin' and it can't find a field in MyEntity with the name 'checkin'. which is correct there is no such field. how do I make it stop doing this? based on the link above I don't think it should be trying to generate a query for this method, but it seems to be doing it anyway. I may be missing something, that is usually the case, but I don't see what it is.

Cœur
39k25 gold badges206 silver badges282 bronze badges
asked Jul 28, 2017 at 22:21

1 Answer 1

2

As stated in the reference documentation section you linked to, you need a MyDaoImpl class that implements the custom methods. I guess the easiest way is to either rename BatchTableLockImpl to that or just create an empty MyDaoImpl extending that class.

answered Jul 31, 2017 at 15:25
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Oliver sorry for the confusion and my misinterpretation of the documentation.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.