that's what it is
Oracle9Dialect
here are the files if anyone has time to check
OracleEmployment.hbm.xml
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!--
This mapping demonstrates the use of Hibernate with
all-handwritten SQL!
This version is for Oracle
-->
<hibernate-mapping default-access="field">
<sql-query name="simpleScalar_SP" callable="true">
<return-scalar column="name" type="string"/>
<return-scalar column="value" type="long"/>
{?=call simpleScalar(?)}</sql-query>
</hibernate-mapping>
Hibernate Java
Code:
package hb.sql;
import org.hibernate.*;
import org.hibernate.cfg.*;
import java.sql.Statement;
import java.util.List;
public class Hibernate {
public static void main (String args[]) {
Hibernate hm = new Hibernate();
hm.query();
}
public void query () {
try {
Session s = currentSession();
Statement statement = s.connection().createStatement();
statement.execute("CREATE OR REPLACE FUNCTION simpleScalar (j number) " +
" RETURN SYS_REFCURSOR " +
"AS " +
" st_cursor SYS_REFCURSOR; " +
"BEGIN " +
" OPEN st_cursor FOR " +
" SELECT j as value, \'getAll\' as name from dual; " +
" RETURN st_cursor; " +
"END;");
statement.close();
Query namedQuery = s.getNamedQuery("simpleScalar_SP");
namedQuery.setLong(1,30);
List list = namedQuery.list();
} catch (Exception e) {
System.out.println(e);
}
}
private static final SessionFactory sessionFactory;
static {
try {
sessionFactory = new Configuration().configure().buildSessionFactory();
} catch (Throwable ex) {
}
}
public static final ThreadLocal session = new ThreadLocal();
public static Session currentSession() throws HibernateException {
Session s = (Session) session.get();
// Open a new Session, if this Thread has none yet
if (s == null) {
s = sessionFactory.openSession();
session.set(s);
}
return s;
}
public static void closeSession() throws HibernateException {
Session s = (Session) session.get();
session.set(null);
if (s != null)
s.close();
}
}
Hibernate.cfg.xml
Code:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="hibernate.connection.url">jdbc:oracle:thin:@localhost:1521:sk</property>
<property name="hibernate.connection.username">sk</property>
<property name="hibernate.connection.password">sk</property>
<property name="dialect">org.hibernate.dialect.Oracle9Dialect</property>
<property name="show_sql">true</property>
<property name="transaction.factory_class">
org.hibernate.transaction.JDBCTransactionFactory
</property>
<property name="hibernate.cache.provider_class">
org.hibernate.cache.HashtableCacheProvider
</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<mapping resource="hb/sql/OracleEmployment.hbm.xml"/>
</session-factory>
</hibernate-configuration>
build.xml
Code:
<project name="hibernate" default="compile">
<property file="run.properties"/>
<target name="compile">
<javac srcdir="." destdir=".">
<classpath>
<fileset dir="./lib">
<include name="*.jar"/>
</fileset>
</classpath>
</javac>
</target>
<path id="run.classpath">
<pathelement location="./lib/antlr-2.7.4.jar"/>
<pathelement location="./lib/commons-collections-2.1.1.jar"/>
<pathelement location="./lib/commons-logging-1.0.4.jar"/>
<pathelement location="./lib/cglib-full-2.0.2.jar"/>
<pathelement location="./lib/dom4j-1.5.2.jar"/>
<pathelement location="./lib/hibernate3.jar"/>
<pathelement location="./lib/hsqldb.jar"/>
<pathelement location="./lib/jdbc2_0-stdext.jar"/>
<pathelement location="./lib/jta.jar"/>
<pathelement location="./lib/log4j-1.2.9.jar"/>
<pathelement location="./lib/ojdbc14.jar"/>
<pathelement location="."/>
</path>
<target name="run1" depends="compile">
<java classname="hb.sql.Hibernate"
classpathref="run.classpath" fork="true">
<arg line="${arg}"/>
</java>
</target>
</project>