• Post Reply Bookmark Topic Watch Topic
  • New Topic

Derived Property issue in Hibernate

 
Raj Chukka
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • 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
 
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!