Function not supported from hibernate

I'm unit testing my DAOs using spring. I am using JPA + Hibernate.

For my tests i'm using the following hsqldb version:

<dependency>
    <groupId>hsqldb</groupId>
    <artifactId>hsqldb</artifactId>
    <version>1.8.0.10</version>
    <scope>test</scope>
</dependency>

And here's my persistence.xml for my unit tests:

   <persistence-unit name="unit-test-pu" transaction-type="RESOURCE_LOCAL">   
      <properties>
         <property name="javax.persistence.jdbc.driver" value="org.hsqldb.jdbcDriver"/>
         <property name="javax.persistence.jdbc.user" value="sa"/>
         <property name="javax.persistence.jdbc.password" value=""/>
         <property name="javax.persistence.jdbc.url" value="jdbc:hsqldb:mem:testdb"/>
         <property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/>
         <property name="hibernate.archive.autodetection" value="class"/>
         <property name="hibernate.show_sql" value="true"/>
         <property name="hibernate.use_sql_comments" value="true"/> 
         <property name="hibernate.format_sql" value="true"/>
         <property name="hibernate.hbm2ddl.auto" value="create"/>
      </properties>      
   </persistence-unit>

This is my test class:

@ContextConfiguration("/spring/test-context.xml")
@TestExecutionListeners({TransactionalTestExecutionListener.class})
@Transactional
public class BaseDaoTestCase extends AbstractJUnit4SpringContextTests { 

    @Autowired
    private MockEntityDao dao;

    @Test
    public void testSave_success() {
        MockEntity e = new MockEntity();
        dao.save(e);
        assertNotNull(e.getId());
    }
}

Note: the idea is to test my DAOs against an in memory HSQLDB instance. Each test method runs within a transaction managed by spring.

Unfortunately, when i run this i get the following exception from hibernate:

Caused by: org.hibernate.exception.GenericJDBCException: This function is not supported
    at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:54)
    at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:125)
    at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:110)
    at org.hibernate.engine.jdbc.internal.proxy.ConnectionProxyHandler.continueInvocation(ConnectionProxyHandler.java:146)
    at org.hibernate.engine.jdbc.internal.proxy.AbstractProxyHandler.invoke(AbstractProxyHandler.java:81)
    at $Proxy23.prepareStatement(Unknown Source)
    at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$2.doPrepare(StatementPreparerImpl.java:105)
    at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$StatementPreparationTemplate.prepareStatement(StatementPreparerImpl.java:166)
    at org.hibernate.engine.jdbc.internal.StatementPreparerImpl.prepareStatement(StatementPreparerImpl.java:103)
    at org.hibernate.id.insert.AbstractSelectingDelegate.performInsert(AbstractSelectingDelegate.java:55)
    at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2764)
    at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3275)
    at org.hibernate.action.internal.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:81)
    at org.hibernate.engine.spi.ActionQueue.execute(ActionQueue.java:362)
    at org.hibernate.engine.spi.ActionQueue.addResolvedEntityInsertAction(ActionQueue.java:203)
    at org.hibernate.engine.spi.ActionQueue.addInsertAction(ActionQueue.java:183)
    at org.hibernate.engine.spi.ActionQueue.addAction(ActionQueue.java:167)
    at org.hibernate.event.internal.AbstractSaveEventListener.addInsertAction(AbstractSaveEventListener.java:320)
    at org.hibernate.event.internal.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:287)
    at org.hibernate.event.internal.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:193)
    at org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:126)
    at org.hibernate.ejb.event.EJB3PersistEventListener.saveWithGeneratedId(EJB3PersistEventListener.java:78)
    at org.hibernate.event.internal.DefaultPersistEventListener.entityIsTransient(DefaultPersistEventListener.java:208)
    at org.hibernate.event.internal.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:151)
    at org.hibernate.event.internal.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:78)
    at org.hibernate.internal.SessionImpl.firePersist(SessionImpl.java:757)
    at org.hibernate.internal.SessionImpl.persist(SessionImpl.java:732)
    at org.hibernate.internal.SessionImpl.persist(SessionImpl.java:736)
    at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:854)
    ... 42 more
Caused by: java.sql.SQLException: This function is not supported
    at org.hsqldb.jdbc.Util.sqlException(Unknown Source)
    at org.hsqldb.jdbc.Util.notSupported(Unknown Source)
    at org.hsqldb.jdbc.jdbcConnection.prepareStatement(Unknown Source)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:616)
    at org.hibernate.engine.jdbc.internal.proxy.ConnectionProxyHandler.continueInvocation(ConnectionProxyHandler.java:138)
    ... 67 more

The implementation of my DAO's save() method is as follows:

entityManager.persist(entity);

I'm using the following hibernate version:

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-entitymanager</artifactId>
    <version>4.1.0.Final</version>
    <scope>compile</scope>
</dependency>

Does anyone have a clue on what's going on?

Answers


I had similar Problem. After I update my dependencies (especially hsqldb) to:

    <hibernate-core-version>4.1.5.Final</hibernate-core-version>
    <spring.version>3.1.2.RELEASE</spring.version>
    <hsqldb.version>2.2.8</hsqldb.version>
    ...
    <dependency>
        <groupId>org.hsqldb</groupId>
        <artifactId>hsqldb</artifactId>
        <version>${hsqldb.version}</version>
    </dependency>

my problem is resolved.


Which mocking framework are you using? I'm just learning to work with mocks so this is just a wild guess but make sure you've done everything necessary to initialize the mock. Maybe the problem has something to do with how the test is being setup.


I'm having the same problem working with JPA + Hibernate + HSQLDB, but not spring. Here is my code:

EntityManagerFactory emf = Persistence.createEntityManagerFactory("persistenceUnit");
EntityManager em = emf.createEntityManager();
EntityTransaction tr = em.getTransaction();
tr.begin();
em.persist(new MyEntity());
tr.commit();
em.close();
emf.close();

That throws me the same This function is not supported exception, but if I do it without the transaction, it doesn't. Like this:

EntityManagerFactory emf = Persistence.createEntityManagerFactory("persistenceUnit");
EntityManager em = emf.createEntityManager();
em.persist(new MyEntity());
em.close();
emf.close();

The problem now, is that I don't see the changes reflected on database.


Need Your Help

How to transform Array.forEach to asynchronous with Q.js?

javascript asynchronous breeze q

I need to execute dynamically a function for all items of an array, but Array.forEach execute in sequence and I need execute in asynchronous.

Using git repository as a database backend

database git database-performance database-replication document-database

I'm doing a project that deals with structured document database. I have a tree of categories (~1000 categories, up to ~50 categories on each level), each category contains several thousands (up to...