-->
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.  [ 1 post ] 
Author Message
 Post subject: How to save Array of UserType in Oracle.
PostPosted: Mon Jul 04, 2011 2:36 am 
Newbie

Joined: Fri Jul 01, 2011 7:18 am
Posts: 2
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.