Support for querying against @MappedSuperclass #75

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

Comments

Projects
None yet
3 participants
@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

This comment has been minimized.

Show comment
Hide comment
@PClaus

PClaus Jan 5, 2012

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

PClaus commented Jan 5, 2012

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

@timowest

This comment has been minimized.

Show comment
Hide comment
@timowest

timowest Feb 7, 2012

Member

released in 2.3.1

Member

timowest commented Feb 7, 2012

released in 2.3.1

@timowest timowest closed this Feb 7, 2012

@jaumzera

This comment has been minimized.

Show comment
Hide comment
@jaumzera

jaumzera Sep 26, 2016

Nice. Also worked for me.
Thank you.

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