4

I've implemented a computed property to my configuration which works fine if I'm using HQL only. Sadly there are places where SQL queries are executed which I can't build into HQL. Am I facing a bug or just doing something wrong?

<property name="customerNr" type="int" insert="false" update="false" lazy="false">
<formula>
(SELECT DISTINCT p.CUSTOMER FROM P.P03 p WHERE p.COUNTRY = land)
</formula>
</property>

When a SQL query is executed, which is done by this way:

session.createSQLQuery(queryString).addEntity(P11.class).list()

I receive a NullPointerException.

java.lang.NullPointerException
at org.hibernate.loader.DefaultEntityAliases.intern(DefaultEntityAliases.java:157)
at org.hibernate.loader.DefaultEntityAliases.getSuffixedPropertyAliases(DefaultEntityAliases.java:130)
at org.hibernate.loader.DefaultEntityAliases.(DefaultEntityAliases.java:76) at org.hibernate.loader.ColumnEntityAliases.(ColumnEntityAliases.java:40) at org.hibernate.loader.custom.sql.SQLQueryReturnProcessor.generateCustomReturns(SQLQueryReturnProcessor.java:197) at org.hibernate.loader.custom.sql.SQLCustomQuery.(SQLCustomQuery.java:152) at org.hibernate.engine.query.NativeSQLQueryPlan.(NativeSQLQueryPlan.java:67) at org.hibernate.engine.query.QueryPlanCache.getNativeSQLQueryPlan(QueryPlanCache.java:136) at org.hibernate.impl.AbstractSessionImpl.getNativeSQLQueryPlan(AbstractSessionImpl.java:160) at org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:165) at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:175) at de.acocon.mis.dao.AmpelDaoImpl.getAmpelOMK(AmpelDaoImpl.java:134) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:307

1 Answer 1

4

You must copy the formula into your native SQL query. Hibernate doesn't try to manipulate or understand native SQL, when you use it, you're on your own.

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

2 Comments

Ok I see, my SQL Queries fetching all columns. Atm I dunno how to implement the formula into my native SQL. Maybe someone can point me the way?
Ok, I've implemented my formula into the native SQL query, result is the same: nullpointer.

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.