I need to run a package through Hibernate,
create or replace PACKAGE BODY "ZIMFUNC" AS
...
FUNCTION ISNUMBER(value IN VARCHAR)
RETURN NUMBER DETERMINISTIC
AS
RC NUMBER;
BEGIN
IF (value IS NULL)
THEN
RETURN 0;
END IF;
RC := TO_NUMBER(value);
RETURN 1;
EXCEPTION
WHEN OTHERS THEN
RETURN 0;
END;
...
I call this package through the Java methods
public Causer criarUsuarioOracle(Causer entity) {
String user = entity.getUserlogin().trim();
try {
executeSql(z.getSql4());
} catch (DaoException e) {
System.out.println("O usuario "+entity.getUserlogin()+" foi criado mas ja existe um user do oracle com esse nome.");
e.printStackTrace();
}
entity.setUsercriabd('S');
return entity;
}
public void executeSql(String sql) throws DaoException {
Transaction t = startTransaction();
try{
getSession().createSQLQuery(sql).executeUpdate();
commitTransaction(t);
}catch(HibernateException e){
rollbackTransaction(t);
e.printStackTrace();
throw e;
}finally{
if (isAutoCommit()) {
getSession().close();
}
}
}
but it gives the following error message.
org.hibernate.QueryException: Space is not allowed after parameter prefix ':' 'create or replace PACKAGE BODY "ZIMFUNC" AS FUNCTION ... (SQL FUNCTION ABOVE) ... END'
at org.hibernate.engine.query.ParameterParser.parse(ParameterParser.java:92)
at org.hibernate.engine.query.ParamLocationRecognizer.parseLocations(ParamLocationRecognizer.java:75)
at org.hibernate.engine.query.QueryPlanCache.buildNativeSQLParameterMetadata(QueryPlanCache.java:149)
at org.hibernate.engine.query.QueryPlanCache.getSQLParameterMetadata(QueryPlanCache.java:79)
at org.hibernate.impl.AbstractSessionImpl.createSQLQuery(AbstractSessionImpl.java:146)
at org.hibernate.impl.SessionImpl.createSQLQuery(SessionImpl.java:1656)
at br.gov.es.dataci.commonshibernate.dao.impl.GenericDao.executeSql(GenericDao.java:484)
at br.gov.es.dataci.controleacesso.persistence.dao.impl.CauserDaoImpl.criarUsuarioOracle(CauserDaoImpl.java:251)
at br.gov.es.dataci.controleacesso.persistence.dao.impl.CauserDaoImpl.main(CauserDaoImpl.java:302)
It understands that the character ':' expects a Hibernate parameter
I inserted two backslashes before ':' in the Java String (SQL FUNCTION), but the error persists.
Can anybody help me?