-->
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.  [ 4 posts ] 
Author Message
 Post subject: Stuck with org.hibernate.exception.SQLGrammarException
PostPosted: Thu Mar 29, 2007 11:00 pm 
Newbie

Joined: Tue Mar 20, 2007 5:13 am
Posts: 9
my program generates:

Code:
- SQL Error: 245, SQLState: S0001
- Conversion failed when converting the nvarchar value 'admin' to data type int.
org.hibernate.exception.SQLGrammarException: could not initialize a collection: [com.hibernate.db.Employee.contact#admin]


my hibernate config is:
Code:
<mapping resource="/com/hibernate/db/Employee.hbm.xml" />
<mapping resource="/com/hibernate/db/Contact.hbm.xml" />


Employee.hbm.xml
Code:
<hibernate-mapping>
   <class name="com.hibernate.db.Employee" table="EMPLOYEE">
   
        <id name="employeeUserName" column="EMPLOYEE_USERNAME" type="string" length = "50">
            <generator class="assigned"/>
        </id>
       
        <property name="employeeFName"    column="EMPLOYEE_FIRSTNAME"
                    type="string"
                    length="50"/>
       
        <property name="employeeLName"    column="EMPLOYEE_LASTNAME"
                    type="string"
                    length="50"
                    not-null="true"/>
       
        <property name="employeePassword" column="EMPLOYEE_PASSWORD"
                    type="string"
                    length="10"
                    not-null="true"/>
       
        <property name="employeeDID"    column="EMPLOYEE_DID"
                    type="integer"
                    length="20"/>

        <property name="employeeExt"    column="EMPLOYEE_EXT"
                    type="integer"
                    length="10"/>

        <property name="employeeMobile"   column="EMPLOYEE_MOBILE"
                    type="integer"
                    length="20"/>

        <property name="employeeEmail"    column="EMPLOYEE_EMAIL"
                    type="string"
                    length="50"/>
                    
        <property name="employeePicUrl"   column="EMPLOYEE_PIC_URL"
                  type="string"
                  length="100"/>
                  
        <property name="employeeIsAdmin" column="EMPLOYEE_ISADMIN"
                    type="java.lang.Boolean"/>
       
        <many-to-one name="department" column="DEPARTMENT_ID"
                    class="com.hibernate.db.Department"
                    not-null="true"
                    lazy="false"/>
           
        <set name="contact" cascade="all" lazy="true">
           <key column="CONTACT_ID"/>
           <one-to-many class="com.hibernate.db.Contact" />
        </set>
       
   </class>
</hibernate-mapping>


Contact.hbm.xml
Code:
<hibernate-mapping>
   <class name="com.hibernate.db.Contact" table="CONTACT">
   
        <id name="contactId" column="CONTACT_ID" type="integer" unsaved-value="0">
            <generator class="identity"/>
        </id>
       
        <property name="contactName"    column="CONTACT_NAME"
                    type="string"
                    length="100"/>
       
        <property name="contactType" column="CONTACT_TYPE"
                    type="string"
                    length="10"
                    not-null="true"/>
       
        <property name="contactNumber"    column="CONTACT_NUMBER"
                    type="integer"
                    length="20"/>

        <many-to-one name="employee" column="EMPLOYEE_USERNAME"
                    class="com.hibernate.db.Employee"
                    not-null="true"
                    lazy="false"/>
      
   </class>
</hibernate-mapping>


Employee.java
Code:
   private String employeeUserName;
   private String employeeFName;
   private String employeeLName;
   private String employeePassword;
   private int employeeDID;
   private int employeeExt;
   private int employeeMobile;
   private String employeeEmail;
   private String employeePicUrl;
   private Department department;
   private boolean employeeIsAdmin;
   private Set contact = new HashSet();
       
       ... Getter & Setter ....

       public void addContact(Contact contact) {   this.getContact().add(contact); }
   public void removeContact(Contact contact) { this.getContact().remove(contact); }



Contact.java
Code:
   private int    contactId;
   private String    contactName;
   private String    contactType;
   private int    contactNumber;
   private Employee employee;

        .... Getter and Setter ....


From what I could see ... there should be nothing wrong with the config file, getter and setter.

But when i try to run this code below ...
Code:
...
int contactId = 5;
Contact result = (Contact)session.load(Contact.class, contactId);
session.flush();
session.connection().commit();

//remove department from parent's children
Employee parent = contact.getEmployee();
parent.removeContact(contact);
(new EmployeeDAO()).update(parent);

session.delete(contact);
session.flush();
session.connection().commit();
...


it generates error at parent.removeContact(contact);

and it's pointing at
Code:
at com.hibernate.db.Employee.removeContact(Employee.java:53)


which is the removeContact method at Employee.java ...

I really don't understand as i don't see anywhere in my code that i'm trying to convert nvarchar to data type int ....

Could some one please tell me where did i make my mistake??

I'm so confused now ... because i have something similar with this ... and it works nicely but not this one ...


Last edited by gubrak on Fri Mar 30, 2007 12:06 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 29, 2007 11:27 pm 
Expert
Expert

Joined: Tue Jan 30, 2007 12:45 am
Posts: 283
Location: India
Hi gubrak,

check your DB value .Have you mapped any varchar value to integer. Check which column has value admin.For more clarity include all hibernate package in log 4j.

_________________
Dharmendra Pandey


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 30, 2007 12:05 am 
Newbie

Joined: Tue Mar 20, 2007 5:13 am
Posts: 9
dharmendra.pandey wrote:
Hi gubrak,

check your DB value .Have you mapped any varchar value to integer. Check which column has value admin.For more clarity include all hibernate package in log 4j.


EMPLOYEE table
Code:
EMPLOYEE_USERNAME   varchar(50)
EMPLOYEE_FIRSTNAME   varchar(50)
EMPLOYEE_LASTNAME   varchar(50)
EMPLOYEE_PASSWORD   varchar(10)
EMPLOYEE_DID   int
EMPLOYEE_EXT   int
EMPLOYEE_MOBILE   int
EMPLOYEE_EMAIL   varchar(50)
DEPARTMENT_ID   int
EMPLOYEE_ISADMIN   tinyint
EMPLOYEE_PIC_URL   varchar(100)


CONTACT table
Code:
CONTACT_ID   int
CONTACT_NAME   varchar(100)
CONTACT_TYPE   varchar(10)
CONTACT_NUMBER   int
EMPLOYEE_USERNAME   varchar(50)


"admin" could be found at EMPLOYEE.EMPLOYEE_USERNAME and CONTACT.EMPLOYEE_USERNAME.

As you can see, they're both varchar(50).

My mappings are ...
Employee.hbm.xml
Code:
        <set name="contact" cascade="all" lazy="true">
           <key column="CONTACT_ID"/>
           <one-to-many class="com.hibernate.db.Contact" />
        </set>


and at Contact.hbm.xml
Code:
        <many-to-one name="employee" column="EMPLOYEE_USERNAME"
                    class="com.hibernate.db.Employee"
                    not-null="true"
                    lazy="false"/>


i don't think i made any mapping mistake (varchar -> integer)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 30, 2007 12:43 am 
Newbie

Joined: Tue Mar 20, 2007 5:13 am
Posts: 9
figured out the problem ... dumb stoopid mistake ...


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