Win a copy of Java 9 Modularity: Patterns and Practices for Developing Maintainable Applications this week in the Java 9 forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Derived Property issue in Hibernate  RSS feed

Raj Chukka
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"
"" >

<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> -->
<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"/>


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);

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.

  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!