Hibernate version: 3.0
Database version: Postgres 7.4.7
I have a legacy database with special characters as tablenames that have to be quoted in order to be found:
Code:
Session session = HibernateUtilImport.getSession();
List result = null;
try {
Query q = session.createQuery("select distinct `Resistances` from `Vectors`");
result = q.list();
} catch (HibernateException ex) {
throw new InfrastructureException(ex);
}
return result;
I also tried it with the charaters: \" and '
Hibernate returns following message:
Code:
[java] org.hibernate.QueryException: unexpected char: '`' [select distinct `Resistances` from `Vectors`]
[java] at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:165)
[java] at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:83)
[java] at org.hibernate.impl.SessionFactoryImpl.getQuery(SessionFactoryImpl.java:414)
[java] at org.hibernate.impl.SessionImpl.getQueries(SessionImpl.java:821)
[java] at org.hibernate.impl.SessionImpl.list(SessionImpl.java:779)
[java] at org.hibernate.impl.QueryImpl.list(QueryImpl.java:74)
[java] at at.insilico.madmama.mapper.dao.GenericServiceDAOExport.getObjectsByQuery(GenericServiceDAOExport.java:118)
[java] at at.insilico.madmama.mapper.transformer.CloneTransformer.makeVectorResistance(CloneTransformer.java:330)
[java] at at.insilico.madmama.mapper.Loader.<init>(Loader.java:32)
[java] at at.insilico.madmama.mapper.Main.main(Main.java:8)
[java] Caused by: line 1:17: unexpected char: '`'
[java] at org.hibernate.hql.antlr.HqlBaseLexer.nextToken(HqlBaseLexer.java:279)
[java] at antlr.TokenBuffer.fill(TokenBuffer.java:69)
[java] at antlr.TokenBuffer.LA(TokenBuffer.java:80)
[java] at antlr.LLkParser.LA(LLkParser.java:52)
[java] at org.hibernate.hql.antlr.HqlBaseParser.selectClause(HqlBaseParser.java:873)
[java] at org.hibernate.hql.antlr.HqlBaseParser.selectFrom(HqlBaseParser.java:658)
[java] at org.hibernate.hql.antlr.HqlBaseParser.queryRule(HqlBaseParser.java:573)
[java] at org.hibernate.hql.antlr.HqlBaseParser.selectStatement(HqlBaseParser.java:263)
[java] at org.hibernate.hql.antlr.HqlBaseParser.statement(HqlBaseParser.java:150)
[java] at org.hibernate.hql.ast.QueryTranslatorImpl.parse(QueryTranslatorImpl.java:209)
[java] at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:127)