Reputation: 4778
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
Upvotes: 4
Views: 3561
Reputation: 328556
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.
Upvotes: 4