Querydsl SQL - missing table schema prefix in the generated SQL

379 views
Skip to first unread message

JaPe

unread,
Oct 26, 2011, 8:32:06 AM10/26/11
to quer...@googlegroups.com
Hi, I'm evaluating querydsl's support for SQL queries.

Here's my dependency:
<dependency>
<groupId>com.mysema.querydsl</groupId>
<artifactId>querydsl-sql</artifactId>
<version>2.2.3</version>
</dependency> 

My tables are in H2 and they are in the specific schema ("MT").

The generated Q class looks like this:

/**
 * QSubject is a Querydsl query type for Subject
 */
@Table("SUBJECT")
@Schema("MT")
public class QSubject extends RelationalPathBase<Subject> {

    private static final long serialVersionUID = 399768359;

    public static final QSubject subject = new QSubject("SUBJECT");

    public final NumberPath<Integer> id = createNumber("ID", Integer.class);
...

When I try to create simple select statement using:

SQLTemplates dialect = new H2Templates(); // SQL-dialect
QSubject sub = new QSubject("sub");
SQLQuery query = new SQLQueryImpl(ds.getConnection(), dialect);
List<String> names = query.from(sub)
.where(sub.id.loe(100))
.list(sub.name);

the resulting SQL query is missing the "MT." table schema prefix:

select sub.NAME
from SUBJECT sub
where sub.ID <= ?

What am I doing wrong?

Thanks JaPe

Timo Westkämper

unread,
Oct 26, 2011, 10:18:08 AM10/26/11
to quer...@googlegroups.com
You can serialize the schema by calling setPrintSchema(true) first in the SQLTemplates class.

As it is protected, you can for example create your custom H2Templates instance :

new H2Templates() { {
    setPrintSchema(true);
}};


Timo Westkämper

unread,
Oct 26, 2011, 10:18:52 AM10/26/11
to quer...@googlegroups.com
protected is used instead of public to make mutation of SQLTemplates instances difficult via the public signature.
Reply all
Reply to author
Forward
0 new messages