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.xmlCode:
<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.xmlCode:
<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.javaCode:
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.javaCode:
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 ...