Обсуждение: exception in plsql
show details 5:21 PM (19 minutes ago)
Method in Dao
public void savePerson(Person person, List<Address> addresses, List<Email>
emails, List<Phone> numbers){
call.withProcedureName("
person_save1");
Map<String, Object> out = call.execute(new
PGPerson(person),addresses,null,null);
}
*SP in Database*
CREATE OR REPLACE FUNCTION person_save(person_to_save person, addresses
address[], emails email[], numbers phone[])
RETURNS void AS
$BODY$
DECLARE
per_id bigint;
BEGIN
IF person_to_save.id
IS NULL OR person_to_save.id
= 0 THEN
SELECT INTO per_id nextval('people_id_seq');
INSERT INTO person (id, first_name,last_name,middle_name) values
(per_id, person_to_save.first_name, person_to_save.last_name,
person_to_save.middle_name);
ELSE
per_id := person_to_save.id
;
UPDATE person SET first_name=person_to_save.first_name,
last_name=person_to_save.last_name, middle_name=person_to_save.middle_name
WHERE id = person_to_save.id
;
END IF;
IF addresses IS NOT NULL THEN
EXECUTE person_addresses_save(per_id, addresses);
END IF;
IF emails IS NOT NULL THEN
EXECUTE person_emails_save(per_id, emails);
END IF;
IF numbers IS NOT NULL THEN
EXECUTE person_phones_save(per_id, numbers);
END IF;
END;$BODY$
LANGUAGE 'plpgsql' VOLATILE
COST 100;
ALTER FUNCTION person_save(person, address[], email[], phone[]) OWNER TO
postgres;
COMMENT ON FUNCTION person_save(person, address[], email[], phone[]) IS
'Saves a person. If the person is new they will insert or if they exist
they will update.
Will do the same for the other objects also addresses, emails, phone';
*exception raised is
org.postgresql.util.PSQLException: Cannot cast an instance of
java.util.ArrayList to type Types.ARRAY*
beulah prasanthi wrote: > org.postgresql.util.PSQLException: Cannot cast an instance of > java.util.ArrayList to type Types.ARRAY* An ArrayList is not an array -- it is a List implementation which uses an array, internally. What happens if you use the toArray method to extract an array from the List and pass that in? -Kevin
---------- Forwarded message ---------- From: Ravi <nm.ravi2005@gmail.com> Date: Mon, Feb 22, 2010 at 7:31 PM Subject: Re: [BUGS] exception in plsql To: Kevin Grittner <Kevin.Grittner@wicourts.gov> when I tried to use the toArray method to extract exception raised saying org.postgresql.util.PSQLException: Cannot cast an instance of [Ljava.lang.Object; to type Types.ARRAY -Ravi On Mon, Feb 22, 2010 at 6:46 PM, Kevin Grittner <Kevin.Grittner@wicourts.gov > wrote: > beulah prasanthi wrote: > > > org.postgresql.util.PSQLException: Cannot cast an instance of > > java.util.ArrayList to type Types.ARRAY* > > An ArrayList is not an array -- it is a List implementation which > uses an array, internally. What happens if you use the toArray > method to extract an array from the List and pass that in? > > -Kevin > > -- > Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) > To make changes to your subscription: > http://www.postgresql.org/mailpref/pgsql-bugs > -- Ravi.T BayLogic Technologies India Pvt. Ltd. Vizag. -- Ravi.T BayLogic Technologies India Pvt. Ltd. Vizag.
Ravi <nm.ravi2005@gmail.com> wrote: > when I tried to use the toArray method to extract exception raised > saying > > org.postgresql.util.PSQLException: Cannot cast an instance of > [Ljava.lang.Object; to type Types.ARRAY OK, that looks like an array, so I'm now a bit lost. Could you put together a self-contained example of how to create the problem? (Self-contained meaning that I can take what you provide and run it, without writing any Java or plpgsql code or inventing table or type definitions -- which might or might not match what you did well enough to show the problem.) It's most helpful if you keep removing things until you have the *smallest* example which still shows the problem. -Kevin