Can I use JPARepository with an Elasticsearch datasource? - elasticsearch

Can I use an ES data source with JPA Repository? The main reason I ask is that I would like to use the JPA Specification executor for queries.
Thanks.

No. Specificationand JpaSpecification are based on JPA queries which are different than Spring Data Elasticsearch queries.

Related

How to set multiple data sources in Spring Data R2DBC

I am using spring data r2dbc in my new project and need to connect multiple data sources like A data source and B data source.
Is there a way to connect multiple data sources using r2dbc?
Could I get an example or a document if there is a way?
My stacks are below:
Spring Boot 2.3.0.M4
Spring WebFlux
Spring Data R2DBC
If you want to use multiple datasources in a single application, check my multi r2dbc connection factories example.
If you need a multi-tenant like feature check this multi-tenancy-r2dbc example.
I solved this issue using AbstractRoutingConnectionFactory you can check Add support for AbstractRoutingConnectionFactory

Is it possible to implement read through and write through in apache ignite using jpa?

I wanted to read and write data from underlying db with Apache ignite . I'm doing a spring boot app so i just want to know whether i can use JPA features for it ?
As far as my understanding goes, Apache Ignite does not implement any JPA APIs. So you can't access data stored in Ignite in JPA fashion.
However, you can probably use JPA to cache data in Ignite while writing it to, and reading from, underlying JPA store. In this case you will need to implement your own CacheStore. Example: https://github.com/gridgain/gridgain-advanced-examples/tree/master/src/main/java/org/gridgain/examples/datagrid/store (this is based on Mongo but you can rewrite it to use JPA).

Spring Data Elasticsearch - Field Projections?

As I saw Projections in Spring Data JPA documentation here
but this doesn't seems to exist in Spring Data Elasticsearch.
Is there any best practices for source filtering or projections in Spring Data Elasticsearch?
I already tried creating my custom Repository and put sourceFilter with QueryBuilder. It works but I don't really want to create custom repository.

Spring Jpa Reository

I prepared the HQL query and stored in string variable.
I am using Spring JPA Repositories to deal with database.
I want to execute this HQL query using spring reprository. But I could able to find the way how to invoke this without #Query annotation.
How to run the HQL queries in Spring JPA without #Query annotation?
There are two ways that you can try.
Use #NamedQuery. Check out this.
Write a custom repository and then use criteria builder to interact with the database.

How to implement transactions in MongoDB in Spring [duplicate]

I am using a NoSQL database MongoDB with Java and Spring Data. I am aware that MongoDB only supports transactions for a single document.
I am using Spring Transactions to carry out MongoDB transcations. I am using TransactionTemplate. What should I set in TransactionManager when using TransactionTemplate?
EDIT
I have something like this:
<bean id=”txtTemplateBean” class=”org.springframework.transaction.support.TransactionTemplate”>
<property name=”transactionManager” ref=”txnManagerBean”></property>
I need to define txnManagerBean to point to something like DataSourceTransactionManager for a MongoDB database.
Multi-document ACID transactions are now supported in MongoDB 4.0! See https://www.mongodb.com/blog/post/mongodb-multi-document-acid-transactions-general-availability
MongoDB does support transaction-like semantics using two-phase commits.
There is also another independent effort to support transactions in mongodb using optimistic locking.
MongoDB doesn't support transactions, it only supports atomic operations.
http://docs.mongodb.org/manual/tutorial/model-data-for-atomic-operations/
Here is a post from someone who implemented transactions for MongoDB with optimistic locking:
https://stackoverflow.com/a/12757751/1173560

Resources