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

Exception: "Only root path are allowed" since update from 2.8.1 to 2.9.0 (2.8.2 has same issue) #333

Closed
kienerj opened this Issue Jan 30, 2013 · 3 comments

Comments

Projects
None yet
2 participants
@kienerj

kienerj commented Jan 30, 2013

I have a generic spring-data repository. That repository can be used to query for any subclass of a specific type, Compound. The find method has a parameter of type

Class<? extends EntityPathBase<T>> compoundQueryClass

This is used to cast the QCompound instance to it's according subclass:

QCompound compound = QCompound.compound;

EntityPathBase<T> concreteCompound =
       compound.as(compoundQueryClass);

Then the query is created:

baseQuery.from(concreteCompound)
//...snipped

This worked perfectly fine with QueryDSL 2.8.1 and if compoundQueryClass was of type QSubclass1, only Subclass1 objects were returned, if it was of QSubclass2, only Subclass2 objects were returned. You get the point.

If I update to QueryDSL 2.9.0 (or 2.8.2) the line

baseQuery.from(concreteCompound)

throws an error:

org.springframework.dao.InvalidDataAccessApiUsageException: Only root paths are allowed for joins : compound; nested exception is java.lang.IllegalArgumentException: Only root paths are allowed for joins : compound

and if I use

baseQuery.from(compound)

the query returns all compounds, regardless of their concrete types.

Note: it says it's a spring exception but I only changed QueryDSL version. So the cause must lie within QueryDSL as the issue did not occur in 2.8.1

My current solution is to use a PathBuilder instead:

PathBuilder entityPath =
new PathBuilder<>(ConcreteCompound.class, "compound")

I think the issue is the actual name of the path, eg. "compound" in base class and "concreteCompound" in sub class. That is probably why it works when using the PathBuilder with path name "compound" for concrete compound.

@timowest

This comment has been minimized.

Show comment
Hide comment
@timowest

timowest Jan 31, 2013

Member

The problem is that path.as(QType) doesn't create a root path anymore. The created path is connect to it's parent, so it's not a root path.

path.as(Class) is more of a Querydsl level cast than the creation of a copy, I will try to simplify the semantics.

But in your case why don't you supply the path of the concrete type instead?

This will give you

QCompound compound = new QCompound(path);

instead of

EntityPathBase<T> concreteCompound =
       compound.as(compoundQueryClass);

Alternatively you can also go through the _super field chain of the subtype.

Member

timowest commented Jan 31, 2013

The problem is that path.as(QType) doesn't create a root path anymore. The created path is connect to it's parent, so it's not a root path.

path.as(Class) is more of a Querydsl level cast than the creation of a copy, I will try to simplify the semantics.

But in your case why don't you supply the path of the concrete type instead?

This will give you

QCompound compound = new QCompound(path);

instead of

EntityPathBase<T> concreteCompound =
       compound.as(compoundQueryClass);

Alternatively you can also go through the _super field chain of the subtype.

@timowest

This comment has been minimized.

Show comment
Hide comment
@timowest

timowest Feb 2, 2013

Member

I just made sure that this works now

QCompound compound = QCompound.compound;
EntityPathBase<T> concreteCompound =
   compound.as(compoundQueryClass); 
baseQuery.from(concreteCompound);

Delegates to root paths are now also treated as root paths.

Member

timowest commented Feb 2, 2013

I just made sure that this works now

QCompound compound = QCompound.compound;
EntityPathBase<T> concreteCompound =
   compound.as(compoundQueryClass); 
baseQuery.from(concreteCompound);

Delegates to root paths are now also treated as root paths.

@timowest

This comment has been minimized.

Show comment
Hide comment
@timowest

timowest Feb 20, 2013

Member

Released in 3.0.0.BETA2

Member

timowest commented Feb 20, 2013

Released in 3.0.0.BETA2

@timowest timowest closed this Feb 20, 2013

@timowest timowest added this to the 3.0.0 milestone Apr 14, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment