spring-data

Spring Boot with custom UserDetailsService

回眸只為那壹抹淺笑 提交于 2020-06-07 13:50:30
问题 What is the correct way to add my custom implementation of UserDetailsService (which uses Spring Data JPA) to Spring Boot app? public class DatabaseUserDetailsService implements UserDetailsService { @Inject private UserAccountService userAccountService; @Override public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { User user = userAccountService.getUserByEmail(username); return new MyUserDetails(user); } } public interface UserRepository extends

Spring Boot with custom UserDetailsService

邮差的信 提交于 2020-06-07 13:49:40
问题 What is the correct way to add my custom implementation of UserDetailsService (which uses Spring Data JPA) to Spring Boot app? public class DatabaseUserDetailsService implements UserDetailsService { @Inject private UserAccountService userAccountService; @Override public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { User user = userAccountService.getUserByEmail(username); return new MyUserDetails(user); } } public interface UserRepository extends

R2DBC and enum (PostgreSQL)

穿精又带淫゛_ 提交于 2020-06-01 12:32:27
问题 Does H2DBC support PostgreSQL enums? I checked they git page but it doesn't mention anything about it. If it does, how enums could be used (INSERT, SELECT)? Lets say PostgreSQL enum CREATE TYPE mood AS ENUM ('UNKNOWN', 'HAPPY', 'SAD', ...); Java class @Data public class Person { private String name; private Mood mood; // ... enum Mood{ UNKNOWN, HAPPY, SAD, ...} } I tried: // insert var person = ...; client.insert() .table("people") .using(person) .then() .subscribe(System.out::println); //

R2DBC and enum (PostgreSQL)

旧时模样 提交于 2020-06-01 12:32:06
问题 Does H2DBC support PostgreSQL enums? I checked they git page but it doesn't mention anything about it. If it does, how enums could be used (INSERT, SELECT)? Lets say PostgreSQL enum CREATE TYPE mood AS ENUM ('UNKNOWN', 'HAPPY', 'SAD', ...); Java class @Data public class Person { private String name; private Mood mood; // ... enum Mood{ UNKNOWN, HAPPY, SAD, ...} } I tried: // insert var person = ...; client.insert() .table("people") .using(person) .then() .subscribe(System.out::println); //

Can only create association from one side in Spring Data Rest

僤鯓⒐⒋嵵緔 提交于 2020-06-01 06:49:13
问题 @Entity public class Product { //.. private String name; @OneToMany(mappedBy = "product", orphanRemoval = true) private Set<File> files; //.. } @Entity public class File { //.. @ManyToOne @JoinColumn(name = "product_id", nullable = true) Product product; //.. } I can only create the association from one side so POST /files/{id} { "product" : "http://localhost:8080/api/products/1" } works but POST /products/{id} { "files" : [ "http://localhost:8080/api/files/1" ] } doesn't work. The POST doesn

How to Store MultivalueMap in MySQL using JPA/Hibernate

∥☆過路亽.° 提交于 2020-05-28 09:22:29
问题 I am very new to JPA/Hibernate. In my app, I am using Spring Data JPA. I have a requirement to store MultivalueMap in Mysql DB. I have found examples only based on Map, but not MultiValueMap. At first, is that possible to store MultiValueMap in MySQL DB? Second, I will be glad, if someone show me some good example on above. 回答1: You can store Map<K, List<V>> as Set<Map.Entry<K, List<V>>> this way. @Entity public class Entity { //... @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true)

How to Store MultivalueMap in MySQL using JPA/Hibernate

爱⌒轻易说出口 提交于 2020-05-28 09:22:02
问题 I am very new to JPA/Hibernate. In my app, I am using Spring Data JPA. I have a requirement to store MultivalueMap in Mysql DB. I have found examples only based on Map, but not MultiValueMap. At first, is that possible to store MultiValueMap in MySQL DB? Second, I will be glad, if someone show me some good example on above. 回答1: You can store Map<K, List<V>> as Set<Map.Entry<K, List<V>>> this way. @Entity public class Entity { //... @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true)

How to connect Two Database MySQL and MongoDB in the same project? Is it possible?

耗尽温柔 提交于 2020-05-28 06:02:15
问题 Currently I'm using Hibernate(MySQL) with Spring, the configuration is running fine for me, but once I configured another configuration mongo-config.xml file and trying to run a test case with mongodb it's showing Error creating bean with name .... from first configuration. Below is my mongo-config.xml <context:annotation-config /> <context:component-scan base-package="com.test.mongo" /> <context:property-placeholder location="classpath:mongo-dao.properties" /> <bean id="mongoTemplate" class=

How to connect Two Database MySQL and MongoDB in the same project? Is it possible?

大憨熊 提交于 2020-05-28 06:02:08
问题 Currently I'm using Hibernate(MySQL) with Spring, the configuration is running fine for me, but once I configured another configuration mongo-config.xml file and trying to run a test case with mongodb it's showing Error creating bean with name .... from first configuration. Below is my mongo-config.xml <context:annotation-config /> <context:component-scan base-package="com.test.mongo" /> <context:property-placeholder location="classpath:mongo-dao.properties" /> <bean id="mongoTemplate" class=

Spring Data Exception Handling

余生颓废 提交于 2020-05-26 14:28:06
问题 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