Comments (5)
from spring-data-keyvalue.
Confirmed it doesn't work in 3.2.0-SNAPSHOT either.
from spring-data-keyvalue.
Why are you declaring Spring Data KeyValue as a dependency, but then use Spring Data JPA?
First, Spring Data KeyValue is not meant to be used directly as a Spring Data store implementation.
As described, the Spring Data KeyValue module and framework provides a common abstraction for Key/Value stores, such as Redis using Spring Data Redis, or Hazelcast using Spring Data Hazelcast. In other words, Spring Data KeyValue builds on the core concepts and foundation from Spring Data (Commons) for Key/Value stores specifically.
NOTE: While Spring Data KeyValue "provides" a
Map
implementation (here, and specifically) of the Spring Data CommonsCrudRepository
interface and DAO abstraction (Javadoc, and this), it is not intended to be used as your Spring Boot/Data application's DAO. It is useful, perhaps, for limited testing purposes.
However, because this "Map" implementation was provided by Spring Data KeyValue (in your Spring Boot/Data application classpath), you have entered "multi-module" mode (see documentation).
Now, you must explicitly declare and distinguish, precisely which persistent entity is mapped to which underlying data store (an RDBMS, as you have configured, along with here, or the cheap, Map-based implementation provided by SD KeyValue; I am certain you wanted H2 in your case).
As described in documentation, this is done by either 1) declaring an ("identifying") mapping annotation on your application persistent entity types or 2) declaring your Repository
interface to extend a Spring Data module-specific CrudRepository
type, such as JpaRepository
from Spring Data JPA.
NOTE: The
@KeySpace
entity annotation is not enough by itself to make this distinction, unlike Spring Data module-specific "mapping" annotations, such as JPA's@Entity
annotation for SD JPA, or the@Document
annotation for SD MongoDB, or the@RedisHash
annotation for Spring Data Redis, and so on.
TIP: This is apparent in the SD module, store-specific implementation of
RepositoryConfigurationExtension
, overriddengetIdentifyingAnnotations()
method; for example, in Spring Data Redis, unlike SD KeyValue'sRepositoryConfiguraitonExtension
, which does not declare any "identifying" annotations, only identifying (Repository) types (source).
So, in fact, because your application Repo
extends the "generic" (non-store specific, Spring Data Commons) CrudRepository
, you do (!) need to declare the JPA @Entity
annotation on your application, persistent entity class (KeyValue
, source) in order to clarify which underlying data store will persist and store your entity.
from spring-data-keyvalue.
To be clear, you can either
- (Recommended) Keep your
Repo
definition as is, extendingCrudRepository<KeyValue, String>
, and simply annotate yourKeyValue
entity class with JPA's@Entity
annotation, as you have done before. So...
Given:
@Entity
public KeyValue {
// ...
}
And:
public interface Repo extends CrudRepository<KeyValue, String> { }
Then:
@SpringBootApplication
@EntityScan(basePackageClasses = KeyValue.class)
@EnableJpaRepositories(basePackageClasses = Repo.class)
public class DemoApplication {
// ...
}
- Alternatively, you can simply do the following (keeping all else the same, i.e.
@KeySpace
onKeyValue
, and@EnableMapRepositories
on yourDempApplication
class, as you have done):
public interface Repo extend KeyValueRepository<KeyValue, String> { }
This will resolve the Spring Data specific Exception above, but still, you are going to run into JPA (configuration) Exception at runtime.
Arguably, neither @EnableMapRepositories
and @KeySpace
annotations from Spring Data KeyValue make any sense in the context of JPA.
from spring-data-keyvalue.
You are welcome. Good luck!
from spring-data-keyvalue.
Related Issues (20)
- Upgrade to Maven Wrapper 3.9.6
- Upgrade to Maven Wrapper 3.9.6
- Release 3.1.8 (2023.0.8)
- Release 3.2.2 (2023.1.2)
- Extend license header copyright years to 2024
- Extend license header copyright years to 2024
- Extend license header copyright years to 2024
- Extend license header copyright years to 2024
- Release 3.1.9 (2023.0.9)
- Release 3.2.3 (2023.1.3)
- Release 3.1.10 (2023.0.10)
- Release 3.2.4 (2023.1.4)
- Release 3.3 M2 (2024.0.0)
- Enable `KeyValuePartTreeQuery` usage for projections
- SpelEvaluationException - retrieving and ordering from redis repository in GraalVM HOT 1
- Add `PersistentPropertyPath` comparator infrastructure
- Release 3.1.11 (2023.0.11)
- Release 3.2.5 (2023.1.5)
- Release 3.3 RC1 (2024.0.0)
- Incompatible with JPMS HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from spring-data-keyvalue.