title: Could not prepare statement while saving via entity manager
body: <p>I've got the following error:</p>
  
  <pre><code>07:27:02,736  INFO Version:37 - HCANN000001: Hibernate Commons Annotations {4.0.1.Final}
  07:27:02,745  INFO Version:41 - HHH000412: Hibernate Core {4.2.0.Final}
  07:27:02,755  INFO Environment:239 - HHH000206: hibernate.properties not found
  07:27:02,757  INFO Environment:342 - HHH000021: Bytecode provider name : javassist
  07:27:02,799  INFO Configuration:1933 - HHH000043: Configuring from resource: ./hibernate.cfg.xml
  07:27:02,799  INFO Configuration:1952 - HHH000040: Configuration resource: ./hibernate.cfg.xml
  07:27:02,888  WARN DTDEntityResolver:74 - HHH000223: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/. Use namespace http://www.hibernate.org/dtd/ instead. Refer to Hibernate 3.6 Migration Guide!
  07:27:02,960  INFO Configuration:2074 - HHH000041: Configured SessionFactory: null
  07:27:03,677  INFO DriverManagerConnectionProviderImpl:98 - HHH000402: Using Hibernate built-in connection pool (not for production use!)
  07:27:03,712  INFO DriverManagerConnectionProviderImpl:134 - HHH000115: Hibernate connection pool size: 20
  07:27:03,713  INFO DriverManagerConnectionProviderImpl:137 - HHH000006: Autocommit mode: false
  07:27:03,713  INFO DriverManagerConnectionProviderImpl:151 - HHH000401: using driver [com.mysql.jdbc.Driver] at URL [jdbc:mysql://localhost/ForBook]
  07:27:03,713  INFO DriverManagerConnectionProviderImpl:156 - HHH000046: Connection properties: {user=root, password=****}
  07:27:05,539  INFO Dialect:128 - HHH000400: Using dialect: org.hibernate.dialect.MySQLDialect
  07:27:05,570  INFO LobCreatorBuilder:94 - HHH000423: Disabling contextual LOB creation as JDBC driver reported JDBC version [3] less than 4
  07:27:05,608  INFO TransactionFactoryInitiator:68 - HHH000399: Using default transaction strategy (direct JDBC transactions)
  07:27:05,633  INFO ASTQueryTranslatorFactory:48 - HHH000397: Using ASTQueryTranslatorFactory
  07:27:05,822  INFO Version:39 - HSEARCH000034: Hibernate Search 4.3.0.Alpha1
  07:27:05,988  WARN ConfigContext:301 - HSEARCH000075: Configuration setting hibernate.search.lucene_version was not specified, using LUCENE_CURRENT.
  07:27:06,703  INFO SchemaExport:343 - HHH000227: Running hbm2ddl schema export
  07:27:06,704 DEBUG SchemaExport:353 - Import file not found: /import.sql
  07:27:06,706 DEBUG SQL:104 - alter table BEE drop foreign key FK100622C0E7E16
  07:27:07,463 DEBUG SQL:104 - drop table if exists BEE
  07:27:07,829 DEBUG SQL:104 - drop table if exists HONEY
  07:27:07,999 DEBUG SQL:104 - create table BEE (id integer not null auto_increment, city varchar(255), street varchar(255), myEnum varchar(255), nameOfBee varchar(255), honey_id integer not null, primary key (id))
  07:27:08,533 DEBUG SQL:104 - create table HONEY (honey_id integer not null auto_increment, NAME_OF_HONEY varchar(255), taste varchar(255), primary key (honey_id))
  07:27:08,955 DEBUG SQL:104 - alter table BEE add index FK100622C0E7E16 (honey_id), add constraint FK100622C0E7E16 foreign key (honey_id) references HONEY (honey_id)
  07:27:10,344  INFO SchemaExport:405 - HHH000230: Schema export complete
  07:27:10,667  INFO DriverManagerConnectionProviderImpl:98 - HHH000402: Using Hibernate built-in connection pool (not for production use!)
  07:27:10,680  INFO DriverManagerConnectionProviderImpl:134 - HHH000115: Hibernate connection pool size: 20
  07:27:10,681  INFO DriverManagerConnectionProviderImpl:137 - HHH000006: Autocommit mode: true
  07:27:10,681  INFO DriverManagerConnectionProviderImpl:151 - HHH000401: using driver [org.hsqldb.jdbcDriver] at URL [jdbc:hsqldb:.]
  07:27:10,681  INFO DriverManagerConnectionProviderImpl:156 - HHH000046: Connection properties: {user=sa, password=****, autocommit=true, release_mode=auto}
  07:27:10,907  INFO Dialect:128 - HHH000400: Using dialect: org.hibernate.dialect.HSQLDialect
  07:27:10,909  INFO LobCreatorBuilder:94 - HHH000423: Disabling contextual LOB creation as JDBC driver reported JDBC version [3] less than 4
  07:27:10,910  INFO TransactionFactoryInitiator:73 - HHH000268: Transaction strategy: org.hibernate.engine.transaction.internal.jdbc.JdbcTransactionFactory
  07:27:10,910  INFO ASTQueryTranslatorFactory:48 - HHH000397: Using ASTQueryTranslatorFactory
  07:27:10,924  WARN ConfigContext:301 - HSEARCH000075: Configuration setting hibernate.search.lucene_version was not specified, using LUCENE_CURRENT.
  07:27:10,947  INFO SchemaExport:343 - HHH000227: Running hbm2ddl schema export
  07:27:10,948 DEBUG SchemaExport:353 - Import file not found: /import.sql
  07:27:10,948 DEBUG SQL:104 - alter table BEE drop constraint FK100622C0E7E16
  07:27:10,950 ERROR SchemaExport:425 - HHH000389: Unsuccessful: alter table BEE drop constraint FK100622C0E7E16
  07:27:10,950 ERROR SchemaExport:426 - Table not found: BEE in statement [alter table BEE]
  07:27:10,950 DEBUG SQL:104 - drop table BEE if exists
  07:27:10,951 DEBUG SQL:104 - drop table HONEY if exists
  07:27:10,951 DEBUG SQL:104 - create table BEE (id integer generated by default as identity (start with 1), city varchar(255), street varchar(255), myEnum varchar(255), nameOfBee varchar(255), honey_id integer not null, primary key (id))
  07:27:10,953 DEBUG SQL:104 - create table HONEY (honey_id integer generated by default as identity (start with 1), NAME_OF_HONEY varchar(255), taste varchar(255), primary key (honey_id))
  07:27:10,953 DEBUG SQL:104 - alter table BEE add constraint FK100622C0E7E16 foreign key (honey_id) references HONEY
  07:27:10,956  INFO SchemaExport:405 - HHH000230: Schema export complete
  07:27:11,190 DEBUG SQL:104 - insert into HONEY (honey_id, NAME_OF_HONEY, taste) values (null, ?, ?)
  07:27:11,191  WARN SqlExceptionHelper:143 - SQL Error: -20, SQLState: IM001
  07:27:11,191 ERROR SqlExceptionHelper:144 - This function is not supported
  Exception in thread "main" javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: could not prepare statement
      at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1387)
      at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1310)
      at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1316)
      at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:881)
      at ua.hibernate_project.TestWork.main(TestWork.java:88)
  Caused by: org.hibernate.exception.GenericJDBCException: could not prepare statement
      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.internal.StatementPreparerImpl$StatementPreparationTemplate.prepareStatement(StatementPreparerImpl.java:188)
      at org.hibernate.engine.jdbc.internal.StatementPreparerImpl.prepareStatement(StatementPreparerImpl.java:117)
      at org.hibernate.id.insert.AbstractSelectingDelegate.performInsert(AbstractSelectingDelegate.java:55)
      at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2966)
      at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3477)
      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:321)
      at org.hibernate.event.internal.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:286)
      at org.hibernate.event.internal.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:192)
      at org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:125)
      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:852)
      at org.hibernate.internal.SessionImpl.persist(SessionImpl.java:826)
      at org.hibernate.internal.SessionImpl.persist(SessionImpl.java:830)
      at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:875)
      ... 1 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 org.hibernate.engine.jdbc.internal.StatementPreparerImpl$2.doPrepare(StatementPreparerImpl.java:119)
      at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$StatementPreparationTemplate.prepareStatement(StatementPreparerImpl.java:182)
      ... 22 more
  </code></pre>
  
  <p>While I try to work with entity manager (via Hibernate API all works good)</p>
  
  <p>I can see entity manager tries to insert id, i.e. honey_id   </p>
  
  <pre><code>DEBUG SQL:104 - insert into HONEY (honey_id, NAME_OF_HONEY, taste) values (null, ?, ?)
  </code></pre>
  
  <p>via Hibernate API I see follow</p>
  
  <pre><code>DEBUG SQL:104 - insert into HONEY (NAME_OF_HONEY, taste) values (?, ?)
  </code></pre>
  
  <p>My classes</p>
  
  <p>Bee:</p>
  
  <pre><code>@Entity
  @Table(name = "BEE")
  public class Bee {
  
  @ManyToOne
  @JoinColumn(name = "honey_id", nullable = false)
  private Honey honey;
  
  @Id
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  private int id;
  
  private String nameOfBee;
  
  @Enumerated(EnumType.STRING)
  private MyEnum myEnum = MyEnum.UNNORMAL;
  
  @Embedded
  private Address address;
  </code></pre>
  
  <p>Honey:</p>
  
  <pre><code>@Table(name = "HONEY")
  @Entity
  public class Honey {
  
  @Id
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  @Column(name = "honey_id")
  private int id;
  
  @Column(name = "NAME_OF_HONEY")
  private String nameOfHoney;
  
  private String taste;
  
  @OneToMany(fetch = FetchType.LAZY, cascade = { CascadeType.ALL }, mappedBy = "honey" )
  
  private Set&lt;Bee&gt; bees;
  </code></pre>
  
  <p>Address:</p>
  
  <pre><code>@Embeddable
  public class Address {
  
  public Address() {}
  </code></pre>
  
  <p>TestWork:</p>
  
  <pre><code>public class TestWork {
  
  private static SessionFactory sessionFactory;
  private static EntityManagerFactory emf;
  private Session session;
  
  static{
      Configuration configuration = new Configuration();
      configuration.configure("./hibernate.cfg.xml");
      ServiceRegistryBuilder serviceRegistryBuilder = 
              new ServiceRegistryBuilder().applySettings(configuration.getProperties());
      sessionFactory = configuration.buildSessionFactory(serviceRegistryBuilder.buildServiceRegistry());
      emf = Persistence.createEntityManagerFactory("hibernate-search-example");
  }
  
  public Session openSessionAndGetTransaction(){
  
      session = sessionFactory.openSession();
      session.getTransaction().begin();
  
      return session; 
  }
  
  public static EntityManager getEntityManager(){
      return emf.createEntityManager();
  }
  
  public void commitAndCloseSession(){
      session.getTransaction().commit();
      session.close();    
  }
  
  
  public static void main(String[] args) {
  
      TestWork testWork = new TestWork();
  
      EntityManager em = TestWork.getEntityManager();
      EntityTransaction tx =  em.getTransaction();
      tx.begin();
      Address address = new Address("Dnipro", "K.Marksa");
      Honey honeyFromForest = new Honey("FirstHoney","Very tasty");
  
      Bee firstBee = new Bee();
      firstBee.setAddress(address);
      firstBee.setNameOfBee("I'm first Bee");
      firstBee.setHoney(honeyFromForest);
  
      Bee secondBee = new Bee();  
      secondBee.setAddress(address);
      secondBee.setNameOfBee("I'm second Bee");   
      secondBee.setHoney(honeyFromForest);
  
      Set&lt;Bee&gt; bees = new HashSet&lt;Bee&gt;();
      bees.add(firstBee);
      bees.add(secondBee);        
      honeyFromForest.setBees(bees);
  
      em.persist(honeyFromForest);
      em.persist(firstBee);
      em.persist(secondBee);      
  }
  </code></pre>
  
  <p>Thank you for your help!</p>