3
//generic repo public interface MyGenericRepo extends JpaRepository<GenericEntity,Integer> { } //entity class Place extends GenericEntity { private Event event; } //entity class Event extends GenericEntity{ } //entity class Offer extends GenericEntity { private Place place; } //entity class User extends GenericEntity { private Place place; } 

what should I take in GenericEntity and how to create a ModelManager to save and load entities

1
  • yes its similar but how to create service please Commented Jun 11, 2018 at 9:48

1 Answer 1

3

If you wan't create your own repository interface with Integer as a key. You have to difine:

@NoRepositoryBean public interface MyGenericRepo<T> extends JpaRepository<T, Integer> { } 

annotation @NoRepositoryBean is needed to avoid creation of Repository implementation. You can read more on https://stackoverflow.com/a/11585811/3058413.

After it you should difive interface for each entity:

public interface PlaceRepository extends MyGenericRepo<Place> { } 

Spring data automatically will create implementation of this repostory.

Sign up to request clarification or add additional context in comments.

3 Comments

i dont want to create repository per entity
You cannot generify entity class cause spring won't be able to terminate with entity it must use.
if any example please

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.