GithubHelp home page GithubHelp logo

Comments (5)

JustinKSU avatar JustinKSU commented on May 16, 2024 1

from spring-data-keyvalue.

JustinKSU avatar JustinKSU commented on May 16, 2024

Confirmed it doesn't work in 3.2.0-SNAPSHOT either.

from spring-data-keyvalue.

jxblum avatar jxblum commented on May 16, 2024

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 Commons CrudRepository 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, overridden getIdentifyingAnnotations() method; for example, in Spring Data Redis, unlike SD KeyValue's RepositoryConfiguraitonExtension, 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.

jxblum avatar jxblum commented on May 16, 2024

To be clear, you can either

  1. (Recommended) Keep your Repo definition as is, extending CrudRepository<KeyValue, String>, and simply annotate your KeyValue 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 {

  // ...

}
  1. Alternatively, you can simply do the following (keeping all else the same, i.e. @KeySpace on KeyValue, and @EnableMapRepositories on your DempApplication 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.

jxblum avatar jxblum commented on May 16, 2024

You are welcome. Good luck!

from spring-data-keyvalue.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.