-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Computed property problem
PostPosted: Sun Apr 06, 2008 10:46 am 
Newbie

Joined: Sun Apr 06, 2008 8:49 am
Posts: 3
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.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 18, 2008 10:44 am 
Beginner
Beginner

Joined: Mon Aug 27, 2007 8:10 am
Posts: 37
I think it is a bug in Hibernate - we are experiencing the same symptoms with formula annotations - it works OK when getting an object and fails with NPE when we query on this entity.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 18, 2008 5:10 pm 
Beginner
Beginner

Joined: Thu Dec 11, 2003 12:02 pm
Posts: 23
Does anyone know if this has been solved yet? I am having the same difficulty. No <formula> tag works for me.

e.g.
Code:
<property name="functionalCurrencyCheckAmt" type="big_decimal">
               <formula>(SELECT SUM(EXPENSE_AMT) FROM TPA_FINANCIAL_DETAILS )</formula>
            </property>


They all throw a NPE.

%%%% Error Creating SessionFactory %%%%
java.lang.NullPointerException
at org.hibernate.loader.DefaultEntityAliases.intern(DefaultEntityAliases.java:133)
at org.hibernate.loader.DefaultEntityAliases.getSuffixedPropertyAliases(DefaultEntityAliases.java:106)
at org.hibernate.loader.DefaultEntityAliases.<init>(DefaultEntityAliases.java:52)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.