2

I have the following query. When I execute it I get such error:

[http-nio-8090-exec-9] WARN  org.hibernate.engine.jdbc.spi.SqlExceptionHelper - SQL Error: 0, SQLState: 42601
[http-nio-8090-exec-9] ERROR org.hibernate.engine.jdbc.spi.SqlExceptionHelper - ERROR: syntax error at or near "."
  Position: 5385

I think the problem is in select CG.codes from CodeGroup CG, but how do I write this query correctly? I need to get all the codes that belong to the CodeGroup. The codes is a list of Code.

    StringBuilder queryBuilder = new StringBuilder();
    queryBuilder.append("select distinct AI from AppInfo AI ")
            .append("left join fetch AI.plan as PSAP ")
            .append("where PSAP.edType in ( select C from Code C where C.column1= 'XXXX' ")
            .append("and C in (select CG.codes from CodeGroup CG where CG.name = 'YYYY'))");
4
  • Are you selecting AI column from AppInfo named AS AI? (select distinct AI from AppInfo AI). So I think SQL does not understand which AI do you want to use there join fetch AI.plan. Commented Feb 1, 2018 at 10:15
  • Which columns does table AppInfo have? Commented Feb 1, 2018 at 10:17
  • I select entire AppInfo object from the table. The AI has a column with plan's id based on which I get PSAP from PSAP table. The problem with the query started when I add the last append. Before that everything works fine. Commented Feb 1, 2018 at 10:25
  • That looks like HQL - but the database doesn't understand HQL, only SQL. Commented Feb 1, 2018 at 10:30

2 Answers 2

1

Your line left join fetch AI.plan as PSAP is wrong. Omit the fetch.

Sign up to request clarification or add additional context in comments.

Comments

0

What i have observed that, Your select query has small problem, It should be like this

StringBuilder queryBuilder = new StringBuilder();
    queryBuilder.append("select DISTINCT AI.COLUMN_NAME from AppInfo AI ")
            .append("left join fetch AI.plan as PSAP ")
            .append("where PSAP.edType in ( select C from Code C where C.column1= 'XXXX' ")
            .append("and C in (select CG.codes from CodeGroup CG where CG.name = 'YYYY'))");

Because, AI is the alias name of AppInfo table. Distinct will work on specific column.

1 Comment

Perfect, It's not function it's a keyword. you can use only to get distinct values.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.