Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Passing parameters from child classes to the parents' annotations. [DATAJPA-170] #587

spring-projects-issues opened this issue Feb 14, 2012 · 3 comments
in: core type: enhancement


Copy link

@spring-projects-issues spring-projects-issues commented Feb 14, 2012

Vojtech opened DATAJPA-170 and commented

I am missing a better support for inheritance in Spring Data JPA with annotation. I will start with an example:

I have set of classes which inherit from a single super class:

Aaaa Bbbb Cccc

Each of the Aaaa,Bbbb,Cccc then should contain method findByTag. The problem is that I can't manage to define it generally. Following example defines specific findByTag for Aaaa.

public interface SuperRepository<T> {
@Query("select distinct a from " + TABLE_NAME + " a " +
"join a.tags t " +
"join fetch a.locale where t = ?1")
public List<T> findByTag(Tag t);

Note that the Superclass is @MappedSuperclass and does not have its own table in database.

The problem is, that there is no way to define the TABLE_NAME in the children classes and the only way is to copy all the contents of the SuperRepository to the children repositories.

The duplicity is illustrated with the following GIST:

Affects: 1.0.3

Issue Links:

  • DATAJPA-368 Explain usage of SpEL Expression in @Query(...) on Repository methods
Copy link

@spring-projects-issues spring-projects-issues commented Feb 14, 2012

Vojtech commented

My schema got broken by the formatting - I just wanted to show, that Super is parent of Aaaa, Bbbb and Cccc

Copy link

@spring-projects-issues spring-projects-issues commented Jul 16, 2013

Thomas Darimont commented


please find a prototypic implementation of this feature at:


Copy link

@spring-projects-issues spring-projects-issues commented Jul 17, 2013

Oliver Drotbohm commented

We've introduced the capability to use SpEL and expose the entity name of the concrete repository as #entityName. So you are now able to define queries like this:

@Query("select x from #{#entityName} x …")

Deployed in the latest snapshots so feel free to give it a spin!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
in: core type: enhancement
None yet

No branches or pull requests

2 participants