Domanda

I'm trying to run this query

drop FUNCTION IF EXISTS time_factor;

I want to run it through the Hibernate session with either createSQLQuery() or doWork(). Like this:

sessionFactory.getCurrentSession().createSQLQuery(query).executeUpdate();

or

sessionFactory.getCurrentSession().doWork(new Work() {
        @Override
        public void execute(Connection connection) throws SQLException {
            connection.prepareStatement(query).executeUpdate();
        }
});

This is what I get:

Caused by: org.h2.jdbc.JdbcSQLException: Syntax error in SQL statement "DROP FUNCTION[*] IF EXISTS TIME_FACTOR; "; expected "TABLE, INDEX, USER, SEQUENCE, CONSTANT, TRIGGER, VIEW, ROLE, ALIAS, SCHEMA, ALL, DOMAIN, TYPE, DATATYPE, AGGREGATE";

Does this mean that I can't drop functions through JDBC/Hibernate ?

Also if someone knows a way I can run it I'd be really grateful.

È stato utile?

Soluzione

It is not JDBC/Hibernate that doesn't support DROP FUNCTION but H2 Database.

You can look here for the supported SQL grammar: http://h2database.com/html/grammar.html

If you are looking to create and drop functions with H2, look for ALIAS. You can create Java function aliases with CREATE ALIAS and drop them with DROP ALIAS:

CREATE ALIAS MY_SQRT FOR "java.lang.Math.sqrt";

DROP ALIAS IF EXISTS MY_SQRT;
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top