spring-data

How to do a Mongo aggregation query in Spring Data?

折月煮酒 提交于 2020-07-14 11:13:06
问题 It's the first time I am using Mongo in Java and I am having some problems with this aggregation query. I can do some simple queries in Mongo for Spring with @Query annotation in my Repository interface which extends the MongoRepository<T, ID> . It would be helpful to know which approach to take when you do long aggregations in Spring-Data. db.post.aggregate([ { $match: {} }, { $lookup: { from: "users", localField: "postedBy", foreignField: "_id", as: "user" } }, { $group: { _id: { username:

How to do a Mongo aggregation query in Spring Data?

本秂侑毒 提交于 2020-07-14 11:12:02
问题 It's the first time I am using Mongo in Java and I am having some problems with this aggregation query. I can do some simple queries in Mongo for Spring with @Query annotation in my Repository interface which extends the MongoRepository<T, ID> . It would be helpful to know which approach to take when you do long aggregations in Spring-Data. db.post.aggregate([ { $match: {} }, { $lookup: { from: "users", localField: "postedBy", foreignField: "_id", as: "user" } }, { $group: { _id: { username:

Hibernate session not shared between threads

為{幸葍}努か 提交于 2020-07-09 12:02:08
问题 I have a springboot application that implements a user referral system. One use case is that when a user signs up using a valid referral code from another user, the referrer user gets one reward point, and for every five points they get 10$ in credit. According to this, I have implemented a use case in my application that honors these business rules, and to test proper behavior under high concurrency, I've created an integration test using @DataJpaTest and spring data repositories and H2 DB

Spring Data MongoDB - lazy access to some fields

蓝咒 提交于 2020-07-09 06:44:19
问题 Is it possible to mark field of the class that it will be lazy-loaded? Example: public class Dictionary { private String id; private String someDescription; private String someInfo; private Map<String, String> dictionary; } I want to mark "dictionary" field to be lazy-accessed. Why? This field can be huge and I need it only sometimes, not always. For example I have another object that contains a lot of Dictionary. And its main purpose is to present information from all contained Dictionaries

Spring data jpa findByDate is always returning an empty list

时间秒杀一切 提交于 2020-07-09 06:12:08
问题 I'm using in my application spring-data-jpa 1.9.2, mysql-connector 5.1 and hibernate 4.3.11 Final. My Order class has a "creation" attribute of type date. @Entity public class Order implements Serializable { private static final long serialVersionUID = 1L; @Id @GeneratedValue(strategy = GenerationType.AUTO) private Long id; private java.util.Date creation; } In my JpaRepository I have these two methods to get the orders by date: List<Order> findByCreation(Date date); @Query("select o from

Spring data jpa findByDate is always returning an empty list

倾然丶 夕夏残阳落幕 提交于 2020-07-09 06:10:42
问题 I'm using in my application spring-data-jpa 1.9.2, mysql-connector 5.1 and hibernate 4.3.11 Final. My Order class has a "creation" attribute of type date. @Entity public class Order implements Serializable { private static final long serialVersionUID = 1L; @Id @GeneratedValue(strategy = GenerationType.AUTO) private Long id; private java.util.Date creation; } In my JpaRepository I have these two methods to get the orders by date: List<Order> findByCreation(Date date); @Query("select o from

Spring Specification - conjunction of Predicates

别说谁变了你拦得住时间么 提交于 2020-07-07 01:11:56
问题 I need a function that will be filter parameters and build query. I have 4 parameters therefore if I would try to implement query for each condition I would have to write 16 (2^4) implementations - it's not good idea. I try to improve my code with interface Specification from Spring Data JPA but I cannot create conjunction of predicates. Implementation of Specification interface : public class UserSpecification implements Specification<User> { private final UserSearchCriteria criteria; public

Spring Specification - conjunction of Predicates

人盡茶涼 提交于 2020-07-07 01:11:40
问题 I need a function that will be filter parameters and build query. I have 4 parameters therefore if I would try to implement query for each condition I would have to write 16 (2^4) implementations - it's not good idea. I try to improve my code with interface Specification from Spring Data JPA but I cannot create conjunction of predicates. Implementation of Specification interface : public class UserSpecification implements Specification<User> { private final UserSearchCriteria criteria; public

How can I change/define default database of Mongodb in Spring-data?

孤街浪徒 提交于 2020-07-06 10:56:51
问题 I have interfaces extends from MongoRepository. They are using default database of mongodb. I would like to define the database name for the classes. public interface CustomerRepository extends MongoRepository<Customer, String> { ... } How can I define it? 回答1: You just need to define respective mongobd properties in application.properties file or if you want to yml syntax then define props in application.yml . Under src/main/resources , application.properties should be there already.

How can I change/define default database of Mongodb in Spring-data?

落爺英雄遲暮 提交于 2020-07-06 10:56:32
问题 I have interfaces extends from MongoRepository. They are using default database of mongodb. I would like to define the database name for the classes. public interface CustomerRepository extends MongoRepository<Customer, String> { ... } How can I define it? 回答1: You just need to define respective mongobd properties in application.properties file or if you want to yml syntax then define props in application.yml . Under src/main/resources , application.properties should be there already.