spring-data

Spring data and mongoDB - inheritance and @DBRef

我的梦境 提交于 2020-02-24 11:34:06
问题 I have this two documents, User: @Document(collection = "User") public class User { // fields } and Contact: @Document(collection = "Contact") public class Contact extends User{ // fields } and then I have a document which referes either to User oder Contact: @Document(collection = "DocumentFile") public class DocumentFile { @DBRef private User user; } So I am able to add User oder Contact in DocumentFile#user but if I set a Contact to DocumentFile#user than I lost the reference because in

Hibernate UUID as UUID type

↘锁芯ラ 提交于 2020-02-21 11:13:22
问题 Trying to use a UUID as my id for PostgreSQL and H2, the current exceptions are for H2 java.lang.IllegalArgumentException: Can not set java.util.UUID field com.lm.model.Task.id to java.lang.String at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:167) at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:171) at sun.reflect.UnsafeObjectFieldAccessorImpl.set(UnsafeObjectFieldAccessorImpl.java:81)

Spring Data: Enumeration and Repository issue

眉间皱痕 提交于 2020-02-21 11:00:28
问题 I am using Spring Data and Repositories. I created an Entity with a enum type field, which I declared @Enumerated(EnumType.STRING), but I am forced to create a method getAuthority returning a String. @Entity @Configurable public class BaseAuthority implements GrantedAuthority { @Enumerated(EnumType.STRING) @Column(unique = true) private AuthorityType authority; @Override public String getAuthority() { return authority.toString(); } } The enum is as follow: public enum AuthorityType {

Spring Data: Enumeration and Repository issue

允我心安 提交于 2020-02-21 11:00:21
问题 I am using Spring Data and Repositories. I created an Entity with a enum type field, which I declared @Enumerated(EnumType.STRING), but I am forced to create a method getAuthority returning a String. @Entity @Configurable public class BaseAuthority implements GrantedAuthority { @Enumerated(EnumType.STRING) @Column(unique = true) private AuthorityType authority; @Override public String getAuthority() { return authority.toString(); } } The enum is as follow: public enum AuthorityType {

Advantages of Stream and Spring Data

匆匆过客 提交于 2020-02-21 10:35:05
问题 Some people override the CrudRepository's method findAll to return an Stream (java 8), but I saw they finally transform the Stream to a List in order to send it through a rest controller. Why are they using a Stream ? What is the advantage to use a Stream here? If they want to filter the records I think would be better filter on DataBase. 回答1: This is already supported in Spring Data JPA, look here; so there's not real advantage to override those to return Stream . If you really want a Stream

Advantages of Stream and Spring Data

淺唱寂寞╮ 提交于 2020-02-21 10:34:09
问题 Some people override the CrudRepository's method findAll to return an Stream (java 8), but I saw they finally transform the Stream to a List in order to send it through a rest controller. Why are they using a Stream ? What is the advantage to use a Stream here? If they want to filter the records I think would be better filter on DataBase. 回答1: This is already supported in Spring Data JPA, look here; so there's not real advantage to override those to return Stream . If you really want a Stream

query across two different database table in spring JPA

本秂侑毒 提交于 2020-02-08 05:33:47
问题 I have three tables. Table1 is in DB1 and both table2 and table3 is in DB2 as mentioned below: Table1 in DB1: customerId, accountNumber Table2 in DB2: customerId, accountNumber, id Table3 in DB2: id, name, country I want to get name and country from table3 based on customerId and accountNumber from table1. the tables are related as mentioned above. Tables are not having any mapping, just the columns are same. I am using spring JPA and MySql. Could anyone please help how to perform a join

Connecting GemFire using Spring Boot and Spring Data GemFire

那年仲夏 提交于 2020-02-04 10:34:36
问题 I am trying to connect to an existing GemFire Locator using Spring Data GemFire and Spring Boot. Following is my cache configuration <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:cache="http://www.springframework.org/schema/cache" xmlns:gfe="http://www.springframework.org/schema/gemfire" xmlns:context="http://www.springframework.org/schema/context" xmlns:gfe-data="http://www

How to force transaction commit in Spring Boot test?

老子叫甜甜 提交于 2020-02-04 03:23:08
问题 How can I force a transaction commit in Spring Boot (with Spring Data) while running a method and not after the method ? I've read here that it should be possible with @Transactional(propagation = Propagation.REQUIRES_NEW) in another class but doesn't work for me. Any hints? I'm using Spring Boot v1.5.2.RELEASE. @RunWith(SpringRunner.class) @SpringBootTest public class CommitTest { @Autowired TestRepo repo; @Transactional @Commit @Test public void testCommit() { repo.createPerson(); System

Getting value of invalid field after MethodArgumentNotValidException

家住魔仙堡 提交于 2020-02-03 08:44:49
问题 My entity class is annotated with @NotNull of hibernate for one of the field.I am catching the exception in @ExceptionHelper . My problem is that i want to access the value of the invalid field so that i can add it into the logger. Here is the ExceptionHandler : @ExceptionHandler({ MethodArgumentNotValidException .class }) @ResponseBody public ResponseEntity<?> handleInvalidMethodArgException(MethodArgumentNotValidException de) { List<FieldError> bindingResult = de.getBindingResult()