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

Support for querying against @MappedSuperclass #75

Closed
PClaus opened this issue Jan 3, 2012 · 3 comments
Closed

Support for querying against @MappedSuperclass #75

PClaus opened this issue Jan 3, 2012 · 3 comments

Comments

@PClaus
Copy link

@PClaus PClaus commented Jan 3, 2012

Hi Timo!

I've posted this on StackOverflow:

http://stackoverflow.com/questions/8702542/can-i-remove-the-discriminator-column-in-a-hibernate-single-table-inheritance

and you said to create a ticket here as this "is easily implemented" ;)

Basicly we'll need the @MappedSuperclass annotation to be treated as an @entity annotation when generating querytypes.

Summary of our setup:

We are working with single table inheritance for all entities in our application but don't need or want a discriminator column in the database as it would be redundant and cost a lot of space and performance. Hibernate's alternative instead of using

@entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)

(which is already supported by queryDSL) is to use

@MappedSuperclass

so that no discriminator type is required to map the data from an extended entity back to its abstract parent object.

However: The Query DSL querytype generator does not generate an accessor for @MappedSuperclass.

Example:

@MappedSuperclass
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)@table(name = "client")
public abstract class Client extends AbstractPersistable {
private String name;
// getter, setter...
}

@entity
public class ClientSimple extends Client {

should support a query like this:

query.where(QClient.client.name.equals("..."));

with the query.list ultimately returning a List of Client objects than can then be mapped to ClientSimple objects.

This behaviour is neccessairy, because another application instance of the same base application might extend the Client in a different way (ClientAdvanced) but still has to use most of the same querying methods to find objects of the Client type but then cast them to ClientAdvanced.

@PClaus
Copy link
Author

@PClaus PClaus commented Jan 5, 2012

That was fast! Nice! Will integrate and test as soon as a release is available via maven.

@timowest
Copy link
Member

@timowest timowest commented Feb 7, 2012

released in 2.3.1

@timowest timowest closed this Feb 7, 2012
@jaumzera
Copy link

@jaumzera jaumzera commented Sep 26, 2016

Nice. Also worked for me.
Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants