spring-data

Spring Data Exception Handling

情到浓时终转凉″ 提交于 2020-05-26 14:27:30
问题 I´m working on a project using Spring Data-JPA. I need to handle some exceptions in JpaRepository method calls. In the code bellow, I need to intercept primary key violations erros but I cannot catch the exception directly. In my case, when an exception of this kind occurs, the UnexpectedRollbackException exception is thrown by repository layer (JpaRepository). I need to search inside this exception object to determine what is the cause of the problem. I am wondering if there is a more

MongoRepository findByCreatedAtBetween not returning accurate results

て烟熏妆下的殇ゞ 提交于 2020-05-25 07:26:08
问题 My document structure in Mongo is like this : db.user.find() { "_id" : ObjectId("560fa46930a8e74be720009a"), "createdAt" : ISODate("2015-10-03T09:47:56.333Z"), "message" : "welcome", } { "_id" : ObjectId("560fa46930a8e723e720009a"), "createdAt" : ISODate("2015-10-03T09:48:25.048Z"), "message" : "thank you" } When I use the below query in my Mongo Shell to find documents between two given timestamps, i get the right result : db.user.find({createdAt:{$gte:ISODate("2015-10-03T09:40:25.048Z"),

MongoRepository findByCreatedAtBetween not returning accurate results

可紊 提交于 2020-05-25 07:25:06
问题 My document structure in Mongo is like this : db.user.find() { "_id" : ObjectId("560fa46930a8e74be720009a"), "createdAt" : ISODate("2015-10-03T09:47:56.333Z"), "message" : "welcome", } { "_id" : ObjectId("560fa46930a8e723e720009a"), "createdAt" : ISODate("2015-10-03T09:48:25.048Z"), "message" : "thank you" } When I use the below query in my Mongo Shell to find documents between two given timestamps, i get the right result : db.user.find({createdAt:{$gte:ISODate("2015-10-03T09:40:25.048Z"),

ElasticSearch Java Client querying nested objects

喜你入骨 提交于 2020-05-25 05:12:19
问题 How do I convert this kind of query. { "query": { "nested": { "path": "consultations", "query": { "bool": { "must": [ { "match": { "consultations.prescriptions": "alfuorism" } }, { "match": { "consultations.Diagnosis": "Fever" } } ] } } } } } To a Java Client query using QueryBuilders 回答1: The folowing Java code will generate your query public NestedQueryBuilder nestedBoolQuery(final Map<String, String> propertyValues, final String nestedPath) { BoolQueryBuilder boolQueryBuilder =

How to get a binary stream by GridFS ObjectId with Spring Data MongoDB

大憨熊 提交于 2020-05-24 21:23:29
问题 I can't figure out how to stream a binary file from GridFS with spring-data-mongodb and its GridFSTemplate when I already have the right ObjectId . GridFSTemplate returns either GridFSResource ( getResource() ) or GridFSFile ( findX() ). I can get the GridFSFile by ID: // no way to get the InputStream? GridFSFile file = gridFsTemplate.findOne(Query.query(Criteria.where("_id").is(id))) but there is no obvious way how to get an InputStream for that GridFSFile . Only GridFSResource allows me to

Creating Pagination in Spring Data JPA

半腔热情 提交于 2020-05-23 21:08:49
问题 I am trying to implement pagination feature in Spring Data JPA. I am referring this Blog My Controller contains following code : @RequestMapping(value="/organizationData", method = RequestMethod.GET) public String list(Pageable pageable, Model model){ Page<Organization> members = this.OrganizationRepository.findAll(pageable); model.addAttribute("members", members.getContent()); float nrOfPages = members.getTotalPages(); model.addAttribute("maxPages", nrOfPages); return "members/list"; } My

Creating Pagination in Spring Data JPA

浪尽此生 提交于 2020-05-23 21:07:48
问题 I am trying to implement pagination feature in Spring Data JPA. I am referring this Blog My Controller contains following code : @RequestMapping(value="/organizationData", method = RequestMethod.GET) public String list(Pageable pageable, Model model){ Page<Organization> members = this.OrganizationRepository.findAll(pageable); model.addAttribute("members", members.getContent()); float nrOfPages = members.getTotalPages(); model.addAttribute("maxPages", nrOfPages); return "members/list"; } My

Creating Pagination in Spring Data JPA

这一生的挚爱 提交于 2020-05-23 21:07:46
问题 I am trying to implement pagination feature in Spring Data JPA. I am referring this Blog My Controller contains following code : @RequestMapping(value="/organizationData", method = RequestMethod.GET) public String list(Pageable pageable, Model model){ Page<Organization> members = this.OrganizationRepository.findAll(pageable); model.addAttribute("members", members.getContent()); float nrOfPages = members.getTotalPages(); model.addAttribute("maxPages", nrOfPages); return "members/list"; } My

Sequence does not exist when it does - Postgres/Spring Boot

有些话、适合烂在心里 提交于 2020-05-23 10:32:10
问题 I am writing a Spring Boot web-app and using a Postgres db to persist my data. I created a table in Postgres using create table user (id bigserial primary key not null, name text not null; and identified its sequence_name by looking at the schema (in this case, it is user_id_seq ). Then, in my User entity class in Spring Boot, I added the following: @Entity @Table(name = "user") public class User implements Serializable { @Id @SequenceGenerator(name = "user_local_seq", sequenceName = "user_id

Spring JPA Auditing empty createdBy

落花浮王杯 提交于 2020-05-21 01:31:05
问题 I am using the auditing capabilities of Spring Data and have a class similar to this: @Entity @Audited @EntityListeners(AuditingEntityListener.class) @Table(name="Student") public class Student { @Id @GeneratedValue (strategy = GenerationType.AUTO) private Long id; @CreatedBy private String createdBy; @CreatedDate private Date createdDate; @LastModifiedBy private String lastModifiedBy; @LastModifiedDate private Date lastModifiedDate; ... Now, I believe I have configured auditing fine because