Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I wrote a PostgreSQL function with return value VOID:

CREATE OR REPLACE FUNCTION queryinteriorexteriorcount()
  RETURNS void AS .....

The function works quite well if i call it in pgAdmin. But if i try to call it out from hibernate it wont work, i'll just get the

failed.org.hibernate.MappingException: No Dialect mapping for JDBC type: 1111

I created an own dialect and registered my function:

public class PostgisDialect extends PostgisDialect {

    private static final long serialVersionUID = 3397563913838305367L;

    public PostgresDialect(){
        registerFunction("queryinteriorexteriorcount", new StandardSQLFunction("queryinteriorexteriorcount"));
    }
}

Then i changed the dialect in my hibernate.cfg.xml

<property name="dialect">at.opendata.hibernate.PostgresDialect</property>

And here is how i want to call it:

Query query = session.createSQLQuery("SELECT queryinteriorexteriorcount()");
query.uniqueResult();

Can you please tell me how i can call this function? I dont expect any return value, i just want to call it, the function would do all on itself.

share|improve this question
1  
Hibernate is trying to decode void into something it can understand and failing. Give it a dummy return value? Or see if you can get Hibernate to discard the results - does it have a query operation to execute the function and ignore the result, like executeUpdate or similar? See also: stackoverflow.com/q/12557957/398670 –  Craig Ringer Jun 2 at 14:46
 
I changed the function to return a dummy integer. Now it works! Thanks –  krackmoe Jun 2 at 15:05

1 Answer

If you want to fall back to JDBC, here's how to handle stored procedures and get Connection from Hibernate session.

session.doWork(new Work() {
    @Override
    public void execute(Connection connection) throws SQLException {
        connection.prepareCall("{call queryinteriorexteriorcount()}").executeQuery();
    }
});
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.