Expression Builder to SQL Query

1.4k views Asked by At

I know, that similiar post was posted already (SQL query from Toplink expression), but I didnt find an answer there. I would like to get SQL query from Expression Builder expression:

I have

Expression exp = builder.get(NUMBER.getAttributeName()).equal(getNumber());

and I want to see the SELECT statement, like (Select * from table WHERE number=....)

Or is it possible to execute the expression from Expression Builder without session? (I know that when I used query.prepareCall(session, new DatabaseRow()) I can obtain statement, but I just need to avoid using session. Thank you very much.

2

There are 2 answers

0
James On

You must have the Session (what are you going to execute it on without a Session???).

query.prepareCall(session, new DatabaseRow())

This is how you get the SQL, you need to create a ReadAllQuery with the expression to be able to get the SQL (an Expression is just a where clause).

0
troger19 On

The problem was, that i wasnt able to create session because I couldnt register my project. And that was because I miss one line of code in my Project.class

 setName(APPLICATION_NAME);

After this, I was able to create session and execute query. Thank you anyway