Hi How to save array of UserType in Oracle using Hibernate.
CREATE OR REPLACE TYPE ADDRESS_TY AS OBJECT ( plot number(4), street varchar2(20), city varchar2(20) );
CREATE OR REPLACE TYPE ADDRESS_TY_ARR AS VARRAY(100) OF ADDRESS_TY;
Create Table EMPLOYEE_ARR(EMPID VARCHAR2(10),ADDRESSES ADDRESS_TY_ARR);
EmpAddress.hbm.xml ------------------- <class name="EmpAddressArr" table="EMPLOYEE_ARR"> <!-- cache usage="read-only"/--> <id name="empid" column="EMPID" type="string"/> <property name="empAddressArray" column="ADDRESSES" type="pojos.EmpAddressArrTY"/> </class>
public class AddressVO { private int plot; private String street; private String city; //setters and getters }
public class EmpAddressArrTY implements UserType {
//implemented all other required methods public void nullSafeSet(PreparedStatement arg0, Object arg1, int arg2) throws HibernateException, SQLException { if(arg1==null){ ArrayDescriptor arrdesc=new ArrayDescriptor("ADDRESS_TY_ARR",arg0.getConnection()); ARRAY array =new ARRAY(arrdesc, arg0.getConnection(), null); arg0.setObject(arg2,array); }else{ HashSet set = (HashSet)arg1; Object [] objs = (Object[])set.toArray(); AddressVO []addr = new AddressVO[objs.length]; for(int i=0;i<objs.length;i++) { addr[i] = (AddressVO)objs[i]; } ArrayDescriptor arrdesc=new ArrayDescriptor("ADDRESS_TY_ARR",arg0.getConnection()); ARRAY array =new ARRAY(arrdesc, arg0.getConnection(), addr); arg0.setArray(arg2,array); } } }
Getting following exception: java.sql.SQLException: Fail to convert to internal representation: pojos.AddressVO@83b1b
How to map AddressVO with ADDRESS_TY??
Thanks in advance. -- Raj
|