spring data – Mongodb – findBy Method for nested objects

Just use the @Query annotation on that method. public interface CustomRepository extends MongoRepository<PracticeQuestion, String> { @Query(value = “{ ‘userId’ : ?0, ‘questions.questionID’ : ?1 }”, fields = “{ ‘questions.questionID’ : 1 }”) List<PracticeQuestion> findByUserIdAndQuestionsQuestionID(int userId, int questionID); } By adding the fields part of the @Query annotation, you are telling Mongo to only return that … Read more

org.springframework.data.mapping.PropertyReferenceException: No property catch found for type

I had a issue like this and my mistake was the name of the custom repository class: If the name of your jpa repository interface is LocaleJpaRepository, your new custom interface should be named LocaleJpaRepositoryCustom, but the class that makes the override in the method must be named LocaleJpaRepositoryImpl, as it follows: public class LocalJpaRepositoryImpl … Read more

Creating a read-only repository with SpringData

Yes, the way to go is to add a handcrafted base repository. You usually use something like this: public interface ReadOnlyRepository<T, ID extends Serializable> extends Repository<T, ID> { T findOne(ID id); Iterable<T> findAll(); } You can now have you concrete repos extend that just defined one: public interface PersonRepository extends ReadOnlyRepository<Person, Long> { T findByEmailAddress(String … Read more

How to access entity manager with spring boot and spring data

You would define a CustomRepository to handle such scenarios. Consider you have CustomerRepository which extends the default spring data JPA interface JPARepository<Customer,Long> Create a new interface CustomCustomerRepository with a custom method signature. public interface CustomCustomerRepository { public void customMethod(); } Extend CustomerRepository interface using CustomCustomerRepository public interface CustomerRepository extends JpaRepository<Customer, Long>, CustomCustomerRepository{ } Create an … Read more

“No qualifying bean of type” for JPA repository in Spring Boot

You were scanning the wrong package in your EnableJpaRepositories. There is no org.mdacc.rists.cghub.ws.repository package. So, use this instead: @EnableJpaRepositories(“org.mda.rists.cghub.ws.repository”) Spring Boot does not require any specific code layout to work, however, there are some best practices that will help you. Check out the spring boot documentation on best practices of structuring your code.

Difference between spring-data-jpa and spring-boot-starter-data-jpa

As stated in the docs, the starter one is a convenient inliner for all required dependencies for this particular library, i.e. includes other dependencies in itself, instead of you writing those manually. Look into the spring-boot-starter-data-jpa pom.xml, you will see there it includes spring-data-jpa as a dependency among many others. Spring Boot Starters are a … Read more

updating boolean value in spring data jpa using @Query, with hibernate

I’m using Spring 3.1 and Spring JPA Data. I was having a similar problem. I was constantly getting an error while trying to update multiple records in 1 query. So, I had something like this. @Query(“UPDATE User u SET u.state = ?1 WHERE u.server.id = ?2”) public void updateAllUsers(long state, long serverid); Error: org.hibernate.hql.QueryExecutionRequestException: Not … Read more