Archive for January, 2007
HibernateException: Found two representations of same collection
by Frank Kim on Jan.26, 2007, under Hibernate
Sometimes you might stumble upon this confusing exception.
org.hibernate.HibernateException: Found two representations of same collection: com.betweengo.Foos
This could have happened because after clearing a Hibernate session (session.clear()) you updated a property that contains a collection. I found just making sure to clear the session once seemed to fix the problem but that may not be a suitable solution in more complex situations.
More information about this problem can be found at http://forum.hibernate.org/viewtopic.php?p=2231400.
Catching Oracle exceptions
by Frank Kim on Jan.26, 2007, under Hibernate, Oracle
Oracle SQL queries can throw exceptions. For example in this query f there is no data then Oracle will throw a NO_DATA_FOUND exception.
SELECT status_date INTO v_status_date FROM member WHERE member_id = p_member_id_in;
ORA-01403: no data found
If this query is part of a stored procedure and is called from Hibernate you will get this uninformative exception.
org.hibernate.exception.DataException: could not execute query
Oracle SQL, like many languages, has a try catch construct. In this example you could do the following.
BEGIN
SELECT status_date INTO v_status_date FROM member WHERE member_id = p_member_id_in;
EXCEPTION
WHEN NO_DATA_FOUND THEN
v_status_date := NULL;
END;
Calling Oracle Stored Procedures and Functions
by Frank Kim on Jan.22, 2007, under Oracle
Calling an Oracle function is quite simple. For example
SELECT package.register(1, "Frank", "Kim") FROM dual;
However calling Oracle stored procedures is a bit more tricky, especially if the Oracle stored procedure has output parameters. Here is an example of how to call an Oracle stored procedure that has three input parameters and two output parameters.
DECLARE p_credit_status_out INTEGER;
p_school_status_out INTEGER;
BEGIN
package.get_status(1, "Frank", "Kim", p_credit_status_out, p_school_status_out);
END;
/
Oracle Triggers
by Frank Kim on Jan.05, 2007, under Oracle
Creation
CREATE TRIGGER trig_frank
BEFORE INSERT ON table_frank
FOR EACH ROW
BEGIN
SELECT seq_frank.nextval
INTO :new.id
FROM dual;
END;
.
RUN;
References