How to save array of UserType in Oracle using Hibernate.
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 ADDRESSTYARR
AS VARRAY(100) OF ADDRESS_TY;
Create Table EMPLOYEEARR(EMPID VARCHAR2(10),ADDRESSES ADDRESSTY_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:
[email protected]
Thanks in advance.
View Answers
Ads
Related Tutorials/Questions & Answers:
Advertisements
HOW TO SAVE XML INTO MYSQL AND RETRIEVE IT USING JAVA
HOW TO
SAVE XML INTO MYSQL AND RETRIEVE IT
USING JAVA H ello, i have an xml code, i need to
save it into mysql 5.5 server database
using java. i also want to be able to retrieve it as well. please note that i want it saved
How to delete objects using Hibernate?
How to delete objects
using Hibernate? Hi,
How to delete objects
using Hibernate? I want to delete an object (record) in table.
Thanks
Hi,
Hibernate Session API provides function to delete object.
For deleting
How to using Binary Search Array Java ?
How to
using Binary Search
Array Java ? Hi,
I am beginners in Java Programming Language. I am trying to create small application
using Array functions. The problem is that
how to use binary search
array in Java. Please give
Hibernate save Example - Rose India Hibernate 4 tutorials
in Eclipse tutorial page.
How to
save objects in
Hibernate?
Hibernate is very easy...
Hibernate save Example - Rose India
Hibernate 4 tutorials
In the last section you have learned
how to create
Hibernate application in
Eclipse. We have also
How to save form data to a csv file using jquery or ajax
How to
save form data to a csv file
using jquery or ajax Please let me know more about
how to do this or please suggest me any sites to learn... this.
i am able to read the csv file
using this code
if (window.XMLHttpRequest
How to create binary search tree using an array?
How to create binary search tree
using an
array? hello people,
pls guide me on the topic above.
i have an string
array, i want to make a binary search tree based on data inside this
array.
the
array contains names of people
how to develope a struts application using hibernate?
how to develope a struts application
using hibernate? Hi Folks,
I... and password should validate against database
using hibernate framework...://www.roseindia.net/struts/struts-
hibernate/
http://www.roseindia.net/struts
Hibernate oracle dialect
Hibernate oracle dialect What is the the
Hibernate oracle dialect?
Hi,
Here is the
Hibernate dialect for
oracle database:
org.hibernate.dialect.OracleDialect
Read more at Dialect in
Hibernate.
Thanks