0

Following is my code snippet:

ApplicationContext ctx = new ClassPathXmlApplicationContext(
                    "classpath*:META-INF/spring/applicationContext*.xml");
            JpaTransactionManager jpatm = (JpaTransactionManager) ctx
                    .getBean("transactionManager");
            EntityManager em = jpatm.getEntityManagerFactory()
                    .createEntityManager();
String sqlQuery = "SELECT suc FROM SubUsrCont suc, UDMap uDMap WHERE suc.userid = uDMap.userid AND uDMap.parentuserid = :parentuserid";
TypedQuery<SubUsrCont> query = (TypedQuery<SubUsrCont>) em.createQuery(sqlQuery, SubUsrCont.class);
query.setParameter("parentuserid", parentid);
ArrayList<SubUsrCont> listContent = (ArrayList<SubUsrCont>) query.getResultList();

But when ever executed I get the following error:

[http-8080-1] ERROR org.hibernate.hql.PARSER - line 1:92: expecting OPEN, found '.'

Can anybody help???

3 Answers 3

1

Well, I found it and successfully tested it as well. It was due to my POJO package name. Previously it was in.myproject.myname. I changed it to com.myproject.myname. HQL was taking in as the SQL Keyword IN and was looking for OPEN '('.

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

Comments

0

Why are you using a Native SQL query inside em.createQuery()? This will not work because HQL can not have SELECT and furthermore you don't set the value for parameter :parentuserid.

String sqlQuery = "FROM SubUsrCont suc, UDMap uDMap WHERE suc.userid = uDMap.userid AND uDMap.parentuserid = :parentuserid";
TypedQuery<SubUsrCont> query = (TypedQuery<SubUsrCont>) em.createQuery(sqlQuery, SubUsrCont.class);
query.setParameter("parentuserid", <PARENT USER ID TO BE SEARCHED>);

Try this and see

1 Comment

@shazin... It ain't working.... org.springframework.dao.InvalidDataAccessApiUsageException: org.hibernate.hql.ast.QuerySyntaxException...
0

If you would like to execute SQL use createNativeQuery. Also try "SELECT suc.* ...

Also you don't set the parameter :parentuserid

Use query setParameter("parentuserid",someValue)

1 Comment

@StanislavL... Well it's not working. But I know what the problem is. I have used Spring Roo to generate the project. So the actual table name in the DB in the case of SubUsrCont POJO is sub_usr_cont. Now when I used createNativeQuery it is simply converting the SubUsrCont to subusrcont. Which actually doesn't exists in the DB. I get the following error: ERROR org.hibernate.util.JDBCExceptionReporter - Table 'mydb.subusrcont' doesn't exist

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.