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

Table hint in SqlSubQuery #189

Closed
danbg86 opened this issue Jul 2, 2012 · 3 comments
Closed

Table hint in SqlSubQuery #189

danbg86 opened this issue Jul 2, 2012 · 3 comments

Comments

@danbg86
Copy link

@danbg86 danbg86 commented Jul 2, 2012

Hi,

We are constructing a query and we need to put a table hint in a subquery of SQLServerQuery.

Our goal is the following Query:

from Table1 cr with (NOLOCK)
join (select kwr.campaignId as campaignId, max(kwr.date) as date, sum(kwr.cost) as cost from Table2 kwr with (NOLOCK)
where kwr.date between ? and ? and kwr.keyword = ?
group by kwr.campaignId) as total
on cr.date = total.date and cr.id = total.campaignId
order by cr.id asc

Trying to generate this query we wrote the following code:

SQLTemplates dialect = new SQLServerTemplates();
STable1 t1 = new STable1("cr");
STable2 t2 = new STable2("kwr");
PathBuilder<Object[]> total = new PathBuilder<Object[]>(Object[].class, "total");

SQLServerQuery sqlServerQuery = new SQLServerQuery(getConnection(), dialect);
SQLSubQuery sub = new SQLSubQuery();

List<Object[]> rows = sqlServerQuery.from(t1).tableHints(SQLServerTableHints.NOLOCK)
.join(sub.from(t2).where(t2.date.between(
new Timestamp(dateInicial.getTime()), new Timestamp(dateFinal.getTime())), t2.keyword.eq(keyword))
.groupBy(t2.campaignId)
.list(t2.campaignId.as("campaignId"), t2.date.max().as("date"), t2.cost.sum().as("cost")),
total
).on(t1.date.eq(total.get("date")), t1.id.eq(total.get("campaignId")))
.orderBy(t1.id.asc())
.list(t1.id.as("campaignId"), t1.campaign, total.get("cost"));

We need to put the table hint ("with (NOLOCK)") in subquery, but today this is not possible.

Could you provide this functionality?

Thanks in advance,

Danilo.

@danbg86
Copy link
Author

@danbg86 danbg86 commented Jul 3, 2012

Hi,

Do you have a prediction on when this issue will be implemented? To us this is a critical functionality and can determine if we will adopt QueryDSL in a production environment.

Thanks

Danilo.

@timowest
Copy link
Member

@timowest timowest commented Jul 4, 2012

Just implemented it

@timowest
Copy link
Member

@timowest timowest commented Jul 17, 2012

Released in 2.7.1

@timowest timowest closed this Jul 17, 2012
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
2 participants