spring-data

Add Custom Method to JPARepository with Generics

Deadly 提交于 2021-02-08 09:16:37
问题 Assume I have a Entity called Product . I design a Repo as @Repository interface ProductRepository implements JPARepository<Product, Integer>{} This would inherit all the default methods such as save, findAll etc; Now I want to have one custom method, which is also a common method for other entities. I added another interface and implementation interface CustomRepository<T,ID>{ public void customMethod() } class CustomRepositoryImpl implements CustomRepository<T,ID>{ public void customMethod(

How to Flatten dynamic field with parent document - Spring data Mongo DB

巧了我就是萌 提交于 2021-02-08 08:26:22
问题 In my Spring boot project have a Document like so: @Document(collection="AuditTable") public class AuditTable { @Id private String id; private Map<String, String> properties; where properties is a dynamic field i.e. it can take in as many different key-value pairs. I use MongoRepository to store this value: @Repository public interface AuditTableRepo extends MongoRepository<AuditTable, String> { } Now when I store it in the Collection it looks like this: whereas I want it to look like this: "

How to configure JPA with JPQL in Spring Boot Application - “can't resolve symbol..”

南笙酒味 提交于 2021-02-08 08:22:25
问题 I have a dependency spring-boot-starter-data-jpa Configuration for JPA is inside application.properties : spring.datasource.url=jdbc:mysql://localhost:3306/db?serverTimezone=UTC spring.datasource.username=name spring.datasource.password=pass ... When I create @Entity: @Entity @Table(name="cats") public class Cat { @Column(name="age") private int age; .... } It works well. When i try to use JPQL : "select cat from Cat cat" Intellij idea emphasizes it and says "Can't resolve symbol Cat" , I

How to configure JPA with JPQL in Spring Boot Application - “can't resolve symbol..”

旧时模样 提交于 2021-02-08 08:21:54
问题 I have a dependency spring-boot-starter-data-jpa Configuration for JPA is inside application.properties : spring.datasource.url=jdbc:mysql://localhost:3306/db?serverTimezone=UTC spring.datasource.username=name spring.datasource.password=pass ... When I create @Entity: @Entity @Table(name="cats") public class Cat { @Column(name="age") private int age; .... } It works well. When i try to use JPQL : "select cat from Cat cat" Intellij idea emphasizes it and says "Can't resolve symbol Cat" , I

Spring Kafka ChainedKafkaTransactionManager doesn't synchronize with JPA Spring-data transaction

狂风中的少年 提交于 2021-02-08 07:36:40
问题 I read a ton of Gary Russell answers and posts, but didn't find actual solution for the common use-case for synchronization of the sequence below: recieve from topic A => save to DB via Spring-data => send to topic B As i understand properly: there is no guarantee for fully atomic processing in that case and i need to deal with messages deduplication on the client side, but the main issue is that ChainedKafkaTransactionManager doesn't synchronize with JpaTransactionManager (see @KafkaListener

@Tailable(spring-data-reactive-mongodb) equivalent in spring-data-r2dbc

大城市里の小女人 提交于 2021-02-08 06:43:28
问题 I am trying my hands on spring-data-r2dbc. I am try this on Postgresql. I have tried spring-data-mongodb-reactive before. I couldn't help but to compare both. I see that Query Derivation is not yet supported. But I was wondering if there is an equivalent for @Tailable . This way I would be notified of the database changes in real time. Ca anyone share any code samples with respect to this. I understand that the underlying database should support this. I believe Postgresql does support this

Polymorphic query in spring data

你。 提交于 2021-02-08 05:17:52
问题 I have one base abstract class. @Entity @Table(name = "P_FLD") @Inheritance(strategy = InheritanceType.JOINED) @DiscriminatorColumn(name = "FLD_DISCRIMINATOR", columnDefinition = "CHAR(3)") abstract public class AbstractPassbookField and some classes that extends it. For example: @Entity @DiscriminatorValue("F") @Table(name = "P_FLD_F") public class PassbookFileField extends AbstractPassbookField and i create repository for base entity public interface PassbookRepository extends

Creating Indexname Dynamically using Spring-Data Elasticsearch with @Document

大城市里の小女人 提交于 2021-02-07 20:14:11
问题 I am trying to get indexname dynamically in @Document(indexName="Something",type="type") I have tried using below code: @Document(indexName="#{systemProperties['databaseName'] }", type = "dbtype") but at runtime when I am sending two request from UI to get the data from ES from different indexes,it is not working properly. what should I do to solve this issue? 回答1: A workaround is, to work with NativeSearchQuerries. There you can set the index to whatever you like: NativeSearchQuery query =

How do you autowire/inject your datasource in Spring-boot?

∥☆過路亽.° 提交于 2021-02-07 19:17:58
问题 I have been working with Spring boot for a bit now, and the datasource is always configured in your application.properties in every example I have seen, kind of like this: # DataSource configuration spring.datasource.driver-class-name=org.postgresql.Driver spring.datasource.url=jdbc:postgresql://localhost:5432/abcdef spring.datasource.username=****** spring.datasource.password=****** However, lately I have been trying to integrate Spring Social, and the examples I have seen configure it in

How do i register AbstractMongoEventListener programmatically?

北慕城南 提交于 2021-02-07 10:50:22
问题 In my Spring Boot application, i have a configuration, which reads entries from a Mongo database. After this is done, my subclass of AbstractMongoEventListener is created, even though it operates on a different table and different scope (my own custom @CustomerScope ). Here is the listener: @CustomerScoped @Component public class ProjectsRepositoryListener extends AbstractMongoEventListener<Project> { @Override public void onAfterSave(Project source, DBObject dbo) { System.out.println("saved"