I have an XML Hibernate (3.6.10) mapping with one line which should fill the property duration (type is long) via a formula. The column startTime and endTime is timestamp. From my hbm.xml file:
<property name="duration" formula="extract(epoch from(endTime - startTime))" />
When I run this within a WebLogic server, the following sql is created for this:
select this_.extract(this_.epoch from(this_.endTime - this_.startTime))
as formula4_0_ from MYTABLE this_;
This results in the following exception:
nested exception is org.hibernate.exception.SQLGrammarException: could not execute query
Why is hibernate not recognizing the (postgres) functions epoch and extract? Why is it adding the table name? Is there a way to enforce it?
The hibernate dialect is set to "org.hibernate.dialect.PostgreSQLDialect".
Thx
EDIT: As a workaround or maybe better solution I will implement the getter method for duration on the java entity side. Hopefully the subtraction won't become a performance bottleneck on the application server. ;) This appears to be more reliable with respect to various db dialects.
Nevertheless it would be interesting how the original problem could be solved with hibernate.