-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: H2 Dialect DATE() function doesn't work
PostPosted: Thu Jul 24, 2014 6:12 am 
Newbie

Joined: Sat Feb 05, 2011 11:27 am
Posts: 14
Hi,
I'm using H2 embedded in my java server app. I'm using spring with Hibernate 4.3.6Final.

Some part of hibernate configuration:

Code:
<bean id="dataSource" class="org.apache.tomcat.jdbc.pool.DataSource"
      destroy-method="close" lazy-init="true">      
      <!-- H2 -->
      <property name="driverClassName" value="org.h2.Driver" />
      <property name="url"
         value="jdbc:h2:~/db/test;IFEXISTS=FALSE;AUTO_RECONNECT=TRUE" />

...
...
<property name="jpaVendorAdapter">
         <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
            <property name="showSql" value="false" />
            <property name="generateDdl" value="true" />
            <!-- H2 -->
            <property name="databasePlatform" value="org.hibernate.dialect.H2Dialect" />
         </bean>
      </property>


Unfortunally when I do this typed query:

Code:
String sql = "SELECT msg.id FROM Campagna c LEFT JOIN c.listaComunicazioni msg WHERE (msg.statoTelefonata=:statoTelefonata AND msg.preferenzaTelefonata <> :preferenzaTelefonata) OR (msg.statoSms=:statoSms AND msg.preferenzaSms <> :preferenzaSms) OR (msg.statoEmail=:statoEmail AND msg.preferenzaEmail <> :preferenzaEmail) AND DATE(dataProgrammata)<=DATE(NOW()) ORDER BY msg.tentativiTelefonata ASC";
        TypedQuery<Long> query = entityManager.createQuery(sql, Long.class);


I've this exception in H2:

Code:
24/07/2014 09:36:30 ERROR SqlExceptionHelper:146 - Function "DATE" not found; SQL statement:
select comunicazi2_.id as col_0_0_ from Campagna campagna0_ left outer join Campagna_Comunicazione listacomun1_ on campagna0_.id=listacomun1_.Campagna_id left outer join Comunicazione comunicazi2_ on listacomun1_.listaComunicazioni_id=comunicazi2_.id where comunicazi2_.statoTelefonata=? and comunicazi2_.preferenzaTelefonata<>? or comunicazi2_.statoSms=? and comunicazi2_.preferenzaSms<>? or comunicazi2_.statoEmail=? and comunicazi2_.preferenzaEmail<>? and DATE(dataProgrammata)<=DATE(now()) order by comunicazi2_.tentativiTelefonata ASC [90022-180]


I opened a post in H2 forum https://groups.google.com/forum/#!topic/h2-database/I7GuYj-Bw4Y and they suggest me to post here the problem because maybe is an issue.

Thanks


Top
 Profile  
 
 Post subject: Re: H2 Dialect DATE() function doesn't work
PostPosted: Thu Jul 24, 2014 9:09 am 
Newbie

Joined: Sat Feb 05, 2011 11:27 am
Posts: 14
For now I solved using my custom dialect that add DATE() funcion in this way:

Code:
registerFunction("date", new StandardSQLFunction("truncate", StandardBasicTypes.DATE));Inserisci qui il codice...


Maybe I can open a improvment ticket?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.