Oracle supports query syntax when a table is connected to an Oracle collection type (nested table or VARRAY). This semantics can be used instead of the in (1,2,3) syntax in SQL and allows you to bind an array of values ββto the query. This can be done using the Oracle JDBC driver.
This type of request is called Pickler Fetch. This is much more scalable than using SQL IN Lists. My application can have ~ 10,000 values ββin a collection.
My problem is that I am new to Hibernate (we use Hibernate 3.2.5 and Spring 2.0.6) and do not see how this semantics can be implemented using Hibernate. Typically, a JDBC implementation will work as follows: Define a custom type in the database using the CREATE type in SQL * Plus CREATE OR REPLACE TYPE NUMBER_LIST_TYPE AS TABLE of number;
In Java:
import java.sql.*; import oracle.sql.ArrayDescriptor; import oracle.sql.ARRAY; import oracle.jdbc.*; ArrayDescriptor oracleCollection = ArrayDescriptor.createDescriptor("NUMBER_LIST_TYPE",conn); PreparedStatement stmt = conn.prepareStatement( " SELECT ename,empno FROM emp " +" WHERE empno IN ( " +" SELECT * FROM TABLE( CAST ( ? as NUMBER_LIST_TYPE ) ) " +" ) " ); int[] javaArray1 = { 7369,7566,7782 }; ARRAY jdbcArray1 = new ARRAY (oracleCollection, conn, javaArray1); stmt.setObject(1,jdbcArray1); ResultSet r=stmt.executeQuery(); while(r.next()){ System.out.println( "\t"+"\t"+r.getString(2)+": "+r.getString(1)); }
Now, how can I implement something like this using Hibernate?
source share