• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Derived Property issue in Hibernate

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ,

iam defining one derived propery in Emp.hbm.xml like below.

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >

<hibernate-mapping package="events">
<class name="Emp" table="EMP">
<meta attribute="sync-DAO">false</meta>
<id name="empno" type="int" column="EMPNO">
<generator class="native">
<!-- <param name="sequence">emp_sequence</param> -->
</generator>
</id>
<property name="ename" type="string" column="ENAME"/>
<property name="job" type="string" column="JOB"/>
<property name="mgr" type="int" column="MGR"/>
<property name="hiredate" type="timestamp" column="HIREDATE"/>
<property name="sal" type="double" column="SAL"/>
<property name="comm" type="double" column="COMM"/>
<property name="deptno" type="int" column="DEPTNO" insert="false" update="false" />

<property name="empderived" type="string" formula="select sum(e.sal+e.comm) from Emp e where e.ename = ename" />

<many-to-one name="dept" class="Dept" column="DEPTNO"/>

</class>
</hibernate-mapping>

Here is the code snippet iam using to access the Emp object.

Session session = m.getSession();
Transaction txn = session.beginTransaction();
Emp list = (Emp) session.load(Emp.class, 7782);
System.out.println(list.getEmpderived());

Iam getting the following exception:

Exception in thread "main" org.hibernate.exception.SQLGrammarException: could not load an entity: [events.Emp#7782]

can someone correct me where iam going wrong?

Thanks in advance.

Thanks,
Raj
 
reply
    Bookmark Topic Watch Topic
  • New Topic