I have the following in DAO and when I execute, I am getting
java.sql.SQLException: Fail to convert to internal representation: test.Project@843
DAO Code
List projectList = new LinkedList();
public void saveRecord(List<Project> project)
throws DatabaseException,SQLException {
for (Project items: project) {
insertRecord(items);
}
}
private void insertRecord(Project project) throws SQLException {
projectList.add(project);
try{
ArrayDescriptor desc =
ArrayDescriptor.createDescriptor("MY_ARRAY", dbConn);
// execpetion in this line
ARRAY arr = new ARRAY(desc, dbConn, (Object[])projectList.toArray());
How can I resolve this issue?
Edit 1
CREATE OR REPLACE TYPE project_type as object(
proj_id varchar2 (10),
proj_title varchar2 (10));
create or replace type my_array as Table of project_type;
Thanks, @PrzemyslawKruglej. I took the liberty of cleaning up the deprecated classes.
Unfortunately, this is more complicated than one might expect. You have to use
STRUCT
objects, descriptors and, finally,ARRAY
. Below is a working example.Checking content of the
project_types
table after execution of main class:Output: