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