Hibernate version: 3.2.6ga
Hi,
I have an issue with a computed property in one of my mapping files which I don't understand. The content of this file is as follows:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="org.xxxxx.model.Person" table="Person">
<id name="id" column="Id">
<generator class="native" />
</id>
.....
<property type="java.lang.Integer" name="territoryOfServicexxx"
formula="(SELECT a.vxTerritory FROM Appointment a WHERE a.id=1)" />
</class>
</hibernate-mapping>
I've removed most of the other properties from this file for brevity, but these all function correctly. The line which is causing the issue is this one:
Code:
<property type="java.lang.Integer" name="territoryOfServicexxx"
formula="(SELECT a.vxTerritory FROM Appointment a WHERE a.id=1)" />
There are standard getters and setters in the object which this relate to this property. The query above just returns the value 1 as expected when run on the SQL Server directly (This is a test case so the id isn't dynamic intentionally at this point). Without this property in the mapping file, hibernate works as expected. However, when this property is added to the file I get the following stack trace when trying to run hibernate queries or perform any other hibernate operations:
Code:
java.lang.NullPointerException
org.hibernate.loader.DefaultEntityAliases.intern(DefaultEntityAliases.java:133)
org.hibernate.loader.DefaultEntityAliases.getSuffixedPropertyAliases(DefaultEntityAliases.java:106)
org.hibernate.loader.DefaultEntityAliases.<init>(DefaultEntityAliases.java:52)
org.hibernate.loader.ColumnEntityAliases.<init>(ColumnEntityAliases.java:16)
org.hibernate.loader.custom.sql.SQLQueryReturnProcessor.generateCustomReturns(SQLQueryReturnProcessor.java:174)
org.hibernate.loader.custom.sql.SQLCustomQuery.<init>(SQLCustomQuery.java:129)
org.hibernate.engine.query.NativeSQLQueryPlan.<init>(NativeSQLQueryPlan.java:43)
org.hibernate.engine.query.QueryPlanCache.getNativeSQLQueryPlan(QueryPlanCache.java:114)
org.hibernate.impl.SessionFactoryImpl.checkNamedQueries(SessionFactoryImpl.java:446)
org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:352)
org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1300)
org.xxxxx.utils.HibernateUtil.<clinit>(HibernateUtil.java:13)
org.xxxxx.model.dao.PersonDAO.getById(PersonDAO.java:39)
org.xxxxx.test.Test123.doGet(Test123.java:28)
javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.catalina.servlets.InvokerServlet.serveRequest(InvokerServlet.java:402)
org.apache.catalina.servlets.InvokerServlet.doGet(InvokerServlet.java:134)
javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.xxxxx.filters.SecurityFilter.doFilter(SecurityFilter.java:50)
The method PersonDAO.getById just runs the following code. Again, this all works fine when the computed property isn't present in the mapping file:
Code:
Query q = session.createQuery("from Person p where p.employee=1 and p.id=" + id);
List<Person> result = q.list();
p = (Person) result.get(0);
No SQL is output to the console even when this option is enabled so I can't include that here. The database is running on SQL Server 2005 Express.
I'm somewhat perplexed as to what is going on here and google or the forum search isn't proving very fruitful, so any pointers would be appreciated.