spring-data

Spring MongoTemplate Update Merge

杀马特。学长 韩版系。学妹 提交于 2019-12-25 09:46:10
问题 Using spring's mongoTemplate or otherwise how do I perform a simple merge on an existing mongo document? When I say merge I want the following to happen: If a field in modifier document exists on the backend version of the document, then update it with the new value in the modifier. If a field in the modifier document does NOT exist on the backend version, then add the field. Leave all other fields on the Backend document alone. 回答1: If you wanna perform a merge using MongoTemplate you can do

How to filter array in Mongodb document using Spring

六眼飞鱼酱① 提交于 2019-12-25 09:28:13
问题 I have below document structure. { "_id" : { "teacherId" : "<teacherId>", "Year" : "<Year>" }, "groups" : [ { "groupId" : "<uuid>", "groupName" : "<name>", "groupNameLowerCase" : "<name_in_lower_case>", "description" : "<desc>", "students" : ["<studentid1>", "<studentid2>", ...], "editedDate" : "<currentTimestamp>" }, ... ], "editedDate" : "<currentTimestamp>", "points" : "<points>" } Consider that below two documents are present in DB { "_id" : { "teacherId" : "1", "Year" : "2016" }, "groups

How to return representations of associations in a Spring Data REST resource?

孤街浪徒 提交于 2019-12-25 08:56:32
问题 There are following URLS - /users/2/profile , /users/2/userPosts I need to concat output of both Spring Data REST results in server side and build single JSON from them and send on different URL /users/2/custom . So, I am thinking to make 2 calls to SDR urls from Spring MVC, can we do this using RestTemplate and some JSON concat utility , here server and database is on same machine so RestTemplate will probably have localhost An example will help 回答1: You might rather want to look into the

How can I create a Predicate from a HQL query?

邮差的信 提交于 2019-12-25 08:49:23
问题 I have this repository: @Repository public interface UserRepository extends JpaRepository<User, String>, JpaSpecificationExecutor<User> { @Query("select u from User u, UserRole ur " + "where u.dep = ur.dep " + "and u.allowed = 1") List<User> getAllowed(); } But I want to change the @Query by a custom Spring Data Specification , in order to call it like: repository.findAll(new Allowed()); So I have added extends JpSpecificationExecutor<User> to my repository and now I'm trying to create the

Java Spring: How to see how many entities/rows are affected by a repository.delete method?

♀尐吖头ヾ 提交于 2019-12-25 08:43:10
问题 Within my application (that uses Spring Data and extending the CrudRepository ), I am deleting Entities using: repository.delete(Dog); This triggers a Cascade-delete on other tables/entities. (note: Hibernate is my JPA implementation) Is there a way to see how many rows/entities this has deleted from the Database? 回答1: It isn't, not at least at JPA level. If you take a look to the EntityManager class (which means going one step deeper than Spring Data), you'll see its remove method returns

Override findAll() Spring Data Gemfire Repo Queries

心已入冬 提交于 2019-12-25 08:08:33
问题 I have millions of objects populated in GemFire regions. I don't want default findAll() SDR query to be executed to retrieve the millions of objects in one shot. I am trying to figure out if there is a way to override the default findAll query and provide the LIMIT param to restrict the number of objects retrieved from GemFire Regions. Here is an example of what I want to do: NoRepositoryBean public interface CrudRepository<T, ID extends Serializable> extends Repository<T, ID> { /** * Returns

Neo4j Spring Data example missing annotation @Indexed

老子叫甜甜 提交于 2019-12-25 07:59:15
问题 Trying to run the neo4j spring data example on http://projects.spring.io/spring-data-neo4j/ <dependencies> <dependency> <groupId>org.springframework.data</groupId> <artifactId>spring-data-neo4j</artifactId> <version>4.1.2.RELEASE</version> </dependency> </dependencies> And @NodeEntity public class Movie { @GraphId Long id; @Indexed(type = FULLTEXT, indexName = "search") String title; Person director; @RelatedTo(type="ACTS_IN", direction = INCOMING) Set<Person> actors; @RelatedToVia(type =

How to set @TextIndex name in an entity with Spring-Data-MongoDB

不羁的心 提交于 2019-12-25 07:50:11
问题 I have a entity Person , inherited by Musician and Politician and a repository PersonRepository. I am trying to have all three entities saved into the a collection "person" in MongoDB using PersonRepository.save(..) default method but somehow, Spring-Data-MongoDB save it into 3 separate collections "person", "musician" and "politician". Java Code: @Document public class Person { @Id private String id; @Indexed private String name; @TextIndexed private String biography; } @Document public

Spring 4.3.3 and Spring Data JPA 1.10.4 conflict Spring version

旧时模样 提交于 2019-12-25 07:47:47
问题 We have Spring version 4.3.3, and Spring Data JPA version 1.10.4 According to client tech architect, Spring Data JPA version 1.10.4 has dependency to Spring 4.2.8. So we have 2 versions of Spring in our maven dependency, the declared version 4.3.3 and from Spring data which is Spring version 4.2.8. So, we excluded Spring cores and other spring libraries in Spring Data JPA like this: <dependency> <groupId>org.springframework.data</groupId> <artifactId>spring-data-jpa</artifactId> <version>1.10

Spring Getting Started Guide “Accessing JPA Data with REST” not working

安稳与你 提交于 2019-12-25 07:14:28
问题 I'm learning Spring using the Getting Started Guides. Right now I'm trying to complete "Accessing JPA Data with REST" guide but my code didn't work, so I tried the "complete" version, and it doesn't work too. So far everytime I import content using Spring Tool Suite (STS), the "complete" version executes as expected, according to the description in the guides, but it's not happening right now. The guide instructs me to run the Project as a "Spring Boot App", then to execute a curl command to