-->
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.  [ 3 posts ] 
Author Message
 Post subject: joined-subclass and accesing associations
PostPosted: Tue Apr 03, 2007 2:34 pm 
Regular
Regular

Joined: Wed May 05, 2004 3:41 pm
Posts: 118
Location: New Jersey,USA
Hi,

I have a joined-subclass situation as given below. The sub-class as such works as expected and I'm able to fetch the correct type of sub-class. However when I try to access a collection in the sub-class, it gives me the following exception:

Apr 3, 2007 2:29:10 PM org.hibernate.util.JDBCExceptionReporter logExceptions
WARNING: SQL Error: -1, SQLState: 22018
Apr 3, 2007 2:29:10 PM org.hibernate.util.JDBCExceptionReporter logExceptions
SEVERE: Invalid character string format for type INTEGER.

It looks like a type conversion exception in JDBC but I'm unable to determine where to specify the type to fix this issue.

Hibernate version: 3.2.2

Mapping documents:
User.hbm.xml
Code:
<hibernate-mapping package="com.test.uhg.c4cast.model">

   <class name="User" table="USER_INFO" >
         <id name="userId" column="USER_ID">
            <generator class="assigned"/>
         </id>
         <property name="password" column="PASSWORD" length="10" not-null="true"/>
         <property name="userType" column="USER_TYPE" type="string"/>
         <joined-subclass name="Manager" table="MGR_INFO">
            <key column="LOGIN_ID"/>

            <property name="mgrId" column="MGR_ID" not-null="true" type="long"/>
            
            <property name="firstName" column="FIRST_NAME" not-null="true" length="30" type="string"/>
            <property name="lastName" column="LAST_NAME" length="30" type="string"/>
            <property name="email" column="EMAIL" length="50" type="string"/>
            <property name="phoneNbr" column="CONTACT_NBR" type="string"/>
            <property name="type" column="MGR_TYPE" type="integer"/>
            
            <set name="applications" cascade="save-update" inverse="true">
               <key column="MGR_ID"/>
               <one-to-many class="Application"/>
            </set>
            <set name="contractors" lazy="true" cascade="save-update" inverse="true">
               <key column="MGR_ID"/>
               <one-to-many class="Contractor"/>
            </set>               
         </joined-subclass>
   </class>

</hibernate-mapping>


Application.hbm.xml
Code:
<class name="Application" table="APPLICATION_INFO">
      
      <id name="applicationId" column="APP_ID" unsaved-value="-1">
         <generator class="increment"/>
      </id>
      
      <property name="name" column="NAME" not-null="true" length="30"/>
      <property name="startDate" column="START_DT" not-null="true"/>
      <property name="endDate" column="END_DT"/>
      <property name="psftId" column="PSFT_ID"/>
      <property name="type" column="PRJ_TYPE" not-null="true"/>
      <property name="contractors" column="CNTR_IND"/>

      <many-to-one name="manager" column="MGR_ID"
                class="Manager" not-null="true"/>
      <many-to-one name="rateInfo" class="AppRateInfo"
                   column="RATE_ID" not-null="true"/>
</class>


Code between sessionFactory.openSession() and session.close():
Code:
      SessionFactory factory;
      try {
         //factory = new AnnotationConfiguration().configure("hibernate.cfg.xml").buildSessionFactory();
         factory = new Configuration().configure("hibernate.cfg.xml").buildSessionFactory();
      } catch (Throwable ex) {
//          Log exception!
         throw new ExceptionInInitializerError(ex);
      }
      System.out.println("Factory created");
      Session session = factory.openSession();
      Transaction tx = session.beginTransaction();
      Object o = session.get(User.class,"anandbn");
      System.out.println(o.getClass().getName());   


Full stack trace of any exception that occurs:
Apr 3, 2007 2:29:10 PM org.hibernate.util.JDBCExceptionReporter logExceptions
WARNING: SQL Error: -1, SQLState: 22018
Apr 3, 2007 2:29:10 PM org.hibernate.util.JDBCExceptionReporter logExceptions
SEVERE: Invalid character string format for type INTEGER.
Name and version of the database you are using:
Apache Derby Network Server - 10.2.2.0
The generated SQL (show_sql=true):
Code:
select applicatio0_.MGR_ID as MGR8_1_, applicatio0_.APP_ID as APP1_1_, applicatio0_.APP_ID as APP1_0_0_, applicatio0_.NAME as NAME0_0_, applicatio0_.START_DT as START3_0_0_, applicatio0_.END_DT as END4_0_0_, applicatio0_.PSFT_ID as PSFT5_0_0_, applicatio0_.PRJ_TYPE as PRJ6_0_0_, applicatio0_.CNTR_IND as CNTR7_0_0_, applicatio0_.MGR_ID as MGR8_0_0_, applicatio0_.RATE_ID as RATE9_0_0_ from APPLICATION_INFO applicatio0_ where applicatio0_.MGR_ID=?

Debug level Hibernate log excerpt:


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 03, 2007 5:27 pm 
Expert
Expert

Joined: Tue Nov 23, 2004 7:00 pm
Posts: 570
Location: mostly Frankfurt Germany
You will need to post the classes. Your test code is not accessing the collection as explained in the text as well.

_________________
Best Regards
Sebastian
---
Training for Hibernate and Java Persistence
Tutorials for Hibernate, Spring, EJB, JSF...
eBook: Hibernate 3 - DeveloperGuide
Paper book: Hibernate 3 - Das Praxisbuch
http://www.laliluna.de


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 04, 2007 10:07 am 
Regular
Regular

Joined: Wed May 05, 2004 3:41 pm
Posts: 118
Location: New Jersey,USA
Modified version of the code accessing the collection in the sub-class.

Code:
     
SessionFactory factory;
      try {
         //factory = new AnnotationConfiguration().configure("hibernate.cfg.xml").buildSessionFactory();
         factory = new Configuration().configure("hibernate.cfg.xml").buildSessionFactory();
      } catch (Throwable ex) {
//          Log exception!
         throw new ExceptionInInitializerError(ex);
      }
      System.out.println("Factory created");
      Session session = factory.openSession();
      Transaction tx = session.beginTransaction();
      Manager o = (Mananger)session.get(User.class,"anandbn");
     // Access the collection "applications" on Manager which is a joined-
     //subclass with User
      System.out.println(o.getApplications());

_________________
--------------
Don't forget to Rate the post


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.