SQLException is not thrown in the method body but it is generated by FinderRenderer. See configuration below:
hbm2java config
Code:
<codegen>
<meta attribute="implements">nl.dennie.vikie.model.BBO</meta>
<generate renderer="net.sf.hibernate.tool.hbm2java.BasicRenderer"/>
<generate
package="nl.dennie.vikie.dao"
suffix="DAO"
renderer="net.sf.hibernate.tool.hbm2java.FinderRenderer"/>
</codegen>
Mapping:Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping default-cascade="none" >
<class name="nl.dennie.vikie.model.Range" table="ranges" >
<meta attribute="class-code">
<![CDATA[
public synchronized long reserve(int block){
if(getAmountAvailable()<block){
return -1;
}
else{
setAmountAvailable(getAmountAvailable() - block);
return getTill()-getAmountAvailable();
}
}
]]>
</meta>
<id name="id" type="int" column="ID">
<generator class="identity"/>
</id>
<property name="name" column="NAME" type="string">
<meta attribute="finder-method">findByName</meta>
</property>
<property name="from" column="FROMVAL" type="long" not-null="true"/>
<property name="till" column="TILLVAL" type="long" not-null="true"/>
<property name="amountAvailable" column="AVAILABLE" type="int" not-null="true"/>
<property name="timeOfCreation" column="TIME_OF_CREATION" type="calendar"/>
<many-to-one name="customer" class="nl.dennie.vikie.model.Customer" column="CUSTOMERID" />
<many-to-one name="parent" class="nl.dennie.vikie.model.Range" column="PARENTID" />
</class>
</hibernate-mapping>
Generated FinderCode:
package nl.dennie.vikie.dao;
import java.io.Serializable;
import java.util.List;
import java.sql.SQLException;
import net.sf.hibernate.*;
import net.sf.hibernate.type.Type;
/** Automatically generated Finder class for RangeDAO.
* @author Hibernate FinderGenerator **/
public class RangeDAO implements Serializable {
public static List findByName(Session session, java.lang.String name) throws SQLException, HibernateException {
List finds = session.find("from nl.dennie.vikie.model.Range as range where range.name=?", name, Hibernate.STRING);
return finds;
}
public static List findAll(Session session) throws SQLException, HibernateException {
List finds = session.find("from Range in class nl.dennie.vikie.model.Range");
return finds;
}
}
[/b]