-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: FinderRenderer generates finders which throw SQLException
PostPosted: Tue Nov 23, 2004 7:12 pm 
Regular
Regular

Joined: Tue Jan 27, 2004 12:22 pm
Posts: 103
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 Finder
Code:
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]

_________________
Dencel
- The sun has never seen a shadow -


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 24, 2004 1:37 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
as i remember there is some option for finder renderer which generates code that actually make it throw an exception - but i don't know for sure.

You are welcome to supply a patch if you cnsider it important.

_________________
Max
Don't forget to rate


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.