spring-data

Segregating the read-only and read-write in Spring/J2EE Apps

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-30 07:08:05
问题 We using Spring, Spring-Data and JPA in our project. For production servers, we would like to setup database cluster such that all read queries are directed to one server and all write queries are directed to another server. This obviously will require some changes in the way the DAOs are built. Does anyone know how to achieve this if one has, so far, been following cook-book style DAO creations using Spring-Data/JPA where a DAO implementation is responsible for both reads and writes? What

JPA Specifications by Example

为君一笑 提交于 2019-12-30 06:13:06
问题 Spring Boot here. I'm trying to wrap my head around JpaRepositories and Specifications when used in the context of implementing complex queries and am struggling to see the "forest through the trees" on several items. A canonical example of a Specification is as follows: public class PersonSpecification implements Specification<Person> { private Person filter; public PersonSpecification(Person filter) { super(); this.filter = filter; } public Predicate toPredicate(Root<Person> root,

Spring-Data JPA with Multi-Tenancy Hibernate

断了今生、忘了曾经 提交于 2019-12-30 03:26:28
问题 I am trying to get Spring-Data JPA working with Hibernate with a custom MultiTenantConnectionProvider. Everything in my configuration below seems to work. My MultiTenantConnectionProviderImpl class gets called each time I try to call a Repository method. The main problem is that there is no way to provide a tenant identifier. The Repository interfaces provided by Spring-Data take care of getting the Hibernate Session. Is there any way to provide Spring-Data the tenant identifier? Or is there

How do you use both Spring Data JPA and Spring Data Elasticsearch repositories on the same domain class in a Spring Boot application?

感情迁移 提交于 2019-12-30 03:15:06
问题 I'm trying to use both Spring Data JPA and Spring Data Elasticsearch on the same domain object but it doesn't work. When I tried to run a simple test, I got the following exception: org.springframework.data.mapping.PropertyReferenceException: No property index found for type Person! at org.springframework.data.mapping.PropertyPath.(PropertyPath.java:75) ~[spring-data-commons-1.11.0.RELEASE.jar:na] at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:327) ~[spring-data

Spring Data Rest PUT v.s PATCH LinkableResources

。_饼干妹妹 提交于 2019-12-30 02:17:09
问题 I'm using Spring Data REST to expose my Entity's and their relationships. I have a OneToOne relationship between two Entity's and I'm trying to update/change the relationship with PUT and PATCH. I noticed that Spring Data REST will only allow you to update linked resources - JPA mapped Entity's (OneToMany, ManyToOne, etc) which are also AggregateRoots (has a Repository) - via a PATCH and are ignored with a PUT . This can be seen in the LinkedAssociationSkippingAssociationHandler class: if

how to show query while using query annotations with MongoRepository with spring data

泄露秘密 提交于 2019-12-30 01:36:18
问题 I'm using MongoRepository in spring boot to access mongo: public interface MongoReadRepository extends MongoRepository<User, String> { @Query(value = "{$where: 'this.name == ?0'}", count = true) public Long countName(String name); } and it could work, but i wonder know the exactly query it accessing mongo how to do that? i try to adding some config at properties like below: logging.level.org.springframework.data.mongodb.core.MongoTemplate=DEBUG logging.level.org.springframework.data.mongodb

Spring-Data JPA CrudRepository returns Iterable, is it OK to cast this to List?

百般思念 提交于 2019-12-30 00:54:06
问题 I'm writing a code-gen tool to generate backend wiring code for Spring-boot applications using Spring-Data-Jpa and it's mildly annoying me that the methods in the CrudRepository return Iterable rather than List, as iterable doesn't provide quite enough functionality, but List does, so I'm looking for the best way to convert the iterable into a list. I saw this post on changing an iterable to a collection and I was wondering, rather than using a library like Guava or implementing my own

$filter inside $project MongoDB Using Spring Data

坚强是说给别人听的谎言 提交于 2019-12-29 08:15:31
问题 I have a subdocument that is an array of a parent document. "devices" In that array I've got a property which is a Date property. I want to find the parents documents who contains the child subdocuments by determinated date like this: { "_id" : ObjectId("5818fa596969a1339093a7da"), "fecha" : ISODate("2016-11-01T05:00:00.000Z"), "spot" : "5808e3926969a126c8365c94", "devices" : [ { "evaluationDate" : ISODate("2016-11-01T20:26:00.000Z"), "seenTimesCounter" : 0, "category" : "PRE_PASAJERO",

single custom deserializer for all objects as their ids or embedded whole objects during POST/PUT

左心房为你撑大大i 提交于 2019-12-29 08:03:31
问题 @Entity public Product { @Id public int id; public String name; @ManyToOne(cascade = {CascadeType.DETACH} ) Category category @ManyToMany(fetch = FetchType.EAGER, cascade = {CascadeType.DETACH} ) Set<Category> secondaryCategories; } and this entity: @Entity public Category { @Id public int id; public String name; } I would like to be able to send a POST with json { name: "name", category: 2, secondaryCategories: [3,4,5] } from client-side and be able to be deserialized like: { name: "name",

Use case for Pagination of Embedded resources

試著忘記壹切 提交于 2019-12-29 07:11:39
问题 There is a use case I am struggling with SDR as below - THere is User Table and RefSecQuestion tables User -> ManyTOOne -> RefSecQuestion , RefSecQuestion -> OneToMany -> User THere is User Table and UserFriends tables User -> OneToMany UserFriends , UserFriends -> ManyToOne -> User There is a requirement that when I go /users/{id}/userFriends , then firstname , lastname etc from UserProjection should be shown by default As a result, I enabled excerptProjection in UserRepository and it works