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

Anshuman Jaiswal
  • 5,352
  • 1
  • 29
  • 46
Feroz Mujawar
  • 163
  • 2
  • 8

1 Answers1

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.

eugene-karanda
  • 760
  • 1
  • 6
  • 9