2 Replies Latest reply on Mar 17, 2007 1:44 PM by stefan.lang

    Can not run sampel with ORACLE Strange Exception

      I get the following exeption on server side

      17:31:21,064 INFO [STDOUT] Hibernate: select car_sequence.nextval from dual
      17:31:21,070 ERROR [BasicPropertyAccessor] IllegalArgumentException in class: com.jbossatwork.common.CarDTO, setter method of property: id
      17:31:21,070 ERROR [BasicPropertyAccessor] expected type: int, actual value: java.lang.Integer


      ORACLE is:

      CREATE TABLE CAR
      (
      ID NUMBER,
      MAKE VARCHAR2(50 BYTE),
      MODEL VARCHAR2(50 BYTE),
      MODEL_YEAR VARCHAR2(50 BYTE)
      )

      CAR_SEQUENCE

      Code is (from JBossAtWork Book)


      public class CarDTO
      {
      private int id;
      private String make;
      private String model;
      private String modelYear;

      public CarDTO()
      {
      this.id = -1;
      this.make = "";
      this.model = "";
      this.modelYear = "";
      }

      public CarDTO(String make, String model, String modelYear)
      {
      this.id = -1;
      this.make = make;
      this.model = model;
      this.modelYear = modelYear;
      }

      public CarDTO( int id, String make, String model, String modelYear)
      {
      this.id = id;
      this.make = make;
      this.model = model;
      this.modelYear = modelYear;
      }


      /**
      * @hibernate.id
      * generator-class="sequence"
      * column="ID"
      */
      public int getId()
      {
      return id;
      }

      public void setId(int id)
      {
      this.id = id;
      }

      /**
      * @hibernate.property
      * column="MAKE"
      */
      public String getMake()
      {
      return make;
      }

      public void setMake(String make)
      {
      this.make = make;
      }

      /**
      * @hibernate.property
      * column="MODEL"
      */
      public String getModel()
      {
      return model;
      }

      public void setModel(String model)
      {
      this.model = model;
      }

      /**
      * @hibernate.property
      * column="MODEL_YEAR"
      */
      public String getModelYear()
      {
      return modelYear;
      }

      public void setModelYear(String modelYear)
      {
      this.modelYear = modelYear;
      }
      }




      hibernate mapping is:


      <hibernate-mapping>




      <!--
      To add non XDoclet generator parameters, create a file named
      hibernate-generator-params-CarDTO.xml
      containing the additional parameters and place it in your merge dir.
      -->
      car_sequence









      <!--
      To add non XDoclet property mappings, create a file named
      hibernate-properties-CarDTO.xml
      containing the additional properties and place it in your merge dir.
      -->


      </hibernate-mapping>



      Code snipet to call hibernate on JBoss is:


      session = ServiceLocator.getHibernateSession (HIBERNATE_SESSION_FACTORY);
      tx = session.beginTransaction();
      session.save(car);
      tx.commit();



      The total original code of the book is in addition not working. Here the tyep of ID was in the HBM just "int". Hibernate handbook had as type onyl "integer".

      Jboss is 4.0.5 on HP-UX PA-RISK


        • 1. Corrcet hibernate mapping in readable format (SRY)

           

          
          <hibernate-mapping
          >
           <class
           name="com.jbossatwork.common.CarDTO"
           table="CAR"
           >
          
           <id
           name="id"
           column="ID"
           type="integer"
           >
           <generator class="sequence">
           <!--
           To add non XDoclet generator parameters, create a file named
           hibernate-generator-params-CarDTO.xml
           containing the additional parameters and place it in your merge dir.
           -->
           <param name="sequence">car_sequence</param>
           </generator>
           </id>
          
           <property
           name="make"
           type="java.lang.String"
           column="MAKE"
           />
          
           <property
           name="model"
           type="java.lang.String"
           column="MODEL"
           />
          
           <property
           name="modelYear"
           type="java.lang.String"
           column="MODEL_YEAR"
           />
          
           <!--
           To add non XDoclet property mappings, create a file named
           hibernate-properties-CarDTO.xml
           containing the additional properties and place it in your merge dir.
           -->
          
           </class>
          
          </hibernate-mapping>
          


          • 2. Re: Can not run sampel with ORACLE Strange Exception

            I could solve it myself.

            The problem is the classloader configuration in the default configuration.

            Tomcat loads java.lang.Integer
            JBoss loads java.lang.Integer

            Code calls from Tomcat to Jboss Hibernate and

            CLASH!

            You need to configure Tomcat to use Jboss Class loader, then it works.