title: Hibernate @Where annotation syntax issue
body: <p>I've been having issues with the Where annotation
  I have two tables on MySQL 8.0.18, Venues and Concerts, with this structure and fields</p>
  
  <pre class="lang-sql prettyprint-override"><code>CREATE TABLE VENUE
  (
      ID          INT          NOT NULL AUTO_INCREMENT,
      NAME        VARCHAR(220) NOT NULL,
      IMAGE       VARCHAR(240),
      ACTIVE      BIT          NOT NULL DEFAULT 0,
      COORDINATES VARCHAR(120),
      COUNTRY     VARCHAR(120) NOT NULL DEFAULT 'USA',
      CITY        VARCHAR(220) NOT NULL DEFAULT 'None',
      RATING      INT          NOT NULL DEFAULT 0,
      VERSION     INT          NOT NULL DEFAULT 0,
      PRIMARY KEY (ID)
  );
  
  CREATE TABLE CONCERT
  (
      ID          INT          NOT NULL AUTO_INCREMENT,
      NAME        VARCHAR(120) NOT NULL,
      DESCRIPTION VARCHAR(120) NOT NULL,
      FESTIVAL_ID INT,
      VENUE_ID    INT,
      RATING      INT          NOT NULL DEFAULT 0,
      DATE        DATETIME,
      IMAGE       BLOB,
      VERSION     INT          NOT NULL DEFAULT 0,
      FOREIGN KEY (FESTIVAL_ID) REFERENCES FESTIVAL (ID),
      FOREIGN KEY (VENUE_ID) REFERENCES VENUE (ID),
      PRIMARY KEY (ID)
  );
  </code></pre>
  
  <p>The Java Hibernate and Spring Data JPA configuration is as following</p>
  
  <pre class="lang-java prettyprint-override"><code>package com.heatmanofurioso.gigger.service.persistencehibernateimplementation.config;
  
  import com.heatmanofurioso.gigger.service.persistencehibernateimplementation.HibernateServiceMarker;
  import lombok.extern.slf4j.Slf4j;
  import org.springframework.context.annotation.Bean;
  import org.springframework.context.annotation.ComponentScan;
  import org.springframework.context.annotation.Configuration;
  import org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor;
  import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
  import org.springframework.jdbc.datasource.lookup.JndiDataSourceLookup;
  import org.springframework.orm.jpa.JpaTransactionManager;
  import org.springframework.orm.jpa.JpaVendorAdapter;
  import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
  import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
  import org.springframework.transaction.annotation.EnableTransactionManagement;
  
  import javax.persistence.EntityManagerFactory;
  import javax.sql.DataSource;
  import java.util.Properties;
  
  @Configuration
  @EnableJpaRepositories(basePackageClasses = {HibernateServiceMarker.class})
  @ComponentScan(basePackageClasses = {HibernateServiceMarker.class})
  @Slf4j
  @EnableTransactionManagement
  public class HibernateUtilConfig {
  
      private static final String MYSQL_DATA_SOURCE = "java:jboss/MysqlDataSource";
      private static final String HIBERNATE_ENTITIES = "com.heatmanofurioso.gigger.service.persistencehibernateimplementation.entity";
  
      @Bean
      public DataSource dataSource() {
          JndiDataSourceLookup jndiDataSourceLookup = new JndiDataSourceLookup();
          return jndiDataSourceLookup.getDataSource(MYSQL_DATA_SOURCE);
      }
  
      @Bean
      public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
          LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean();
          entityManagerFactoryBean.setDataSource(dataSource());
          entityManagerFactoryBean.setPackagesToScan(HIBERNATE_ENTITIES);
          log.info("Created entity manager successfully");
          JpaVendorAdapter jpaVendorAdapter = new HibernateJpaVendorAdapter();
  
          //Properties to show SQL format of tables on deploy
          Properties jpaProperties = new Properties();
          jpaProperties.put("hibernate.show_sql", true); // Mark as true to log hibernate queries
          jpaProperties.put("hibernate.format_sql", true); // Mark as true to log hibernate queries
          entityManagerFactoryBean.setJpaProperties(jpaProperties);
  
          entityManagerFactoryBean.setJpaVendorAdapter(jpaVendorAdapter);
          return entityManagerFactoryBean;
      }
  
      @Bean
      public JpaTransactionManager transactionManager(EntityManagerFactory entityManagerFactory) {
          JpaTransactionManager transactionManager = new JpaTransactionManager();
          transactionManager.setEntityManagerFactory(entityManagerFactory);
          return transactionManager;
      }
  
      @Bean
      public PersistenceExceptionTranslationPostProcessor exceptionTranslation() {
          return new PersistenceExceptionTranslationPostProcessor();
      }
  }
  </code></pre>
  
  <pre class="lang-java prettyprint-override"><code>package com.heatmanofurioso.gigger.service.persistencehibernateimplementation.dao;
  
  import com.heatmanofurioso.gigger.service.persistencehibernateimplementation.entity.VenueEntity;
  import org.springframework.data.jpa.repository.JpaRepository;
  import org.springframework.data.jpa.repository.Query;
  import org.springframework.stereotype.Repository;
  
  import java.util.List;
  
  @Repository
  public interface VenueHibernateServiceImpl extends JpaRepository&lt;VenueEntity, Long&gt; {
      @Query("SELECT t FROM VenueEntity t WHERE t.name like ?1")
      List&lt;VenueEntity&gt; getByName(String name);
  
      @Query("SELECT t FROM VenueEntity t WHERE t.coordinates = ?1")
      List&lt;VenueEntity&gt; getByCoordinates(String coordinates);
  }
  </code></pre>
  
  <pre class="lang-java prettyprint-override"><code>package com.heatmanofurioso.gigger.service.persistencehibernateimplementation.dao;
  
  import com.heatmanofurioso.gigger.service.persistencehibernateimplementation.entity.ConcertEntity;
  import org.springframework.data.jpa.repository.JpaRepository;
  import org.springframework.data.jpa.repository.Query;
  import org.springframework.stereotype.Repository;
  
  import java.util.List;
  
  @Repository
  public interface ConcertHibernateServiceImpl extends JpaRepository&lt;ConcertEntity, Long&gt; {
  
      @Query("SELECT t FROM ConcertEntity t WHERE t.name like ?1")
      List&lt;ConcertEntity&gt; getByName(String name);
  }
  </code></pre>
  
  <p>And I am successfully obtaining the following entities using Java 11 Spring JPA 5.2.0.RELEASE and Hibernate 5.4.8 deployed on a Wildfly 18.0.0.Final using the following entities</p>
  
  <pre class="lang-java prettyprint-override"><code>package com.heatmanofurioso.gigger.service.persistencehibernateimplementation.entity;
  
  import org.hibernate.annotations.Where;
  
  import javax.persistence.Column;
  import javax.persistence.Entity;
  import javax.persistence.FetchType;
  import javax.persistence.GeneratedValue;
  import javax.persistence.GenerationType;
  import javax.persistence.Id;
  import javax.persistence.OneToMany;
  import javax.persistence.Table;
  import javax.persistence.Version;
  import java.util.HashSet;
  import java.util.Set;
  
  @Entity
  @Table(name = "VENUE")
  public class VenueEntity {
  
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      @Column(name = "ID", nullable = false)
      private Long id;
  
      @Column(name = "NAME", nullable = false)
      private String name;
  
      @Column(name = "IMAGE", nullable = false)
      private String image;
  
      @Column(name = "ACTIVE", nullable = false)
      private Boolean active;
  
      @Column(name = "COORDINATES")
      private String coordinates;
  
      @Column(name = "RATING")
      private Long rating;
  
      @Column(name = "COUNTRY")
      private String country;
  
      @Column(name = "CITY")
      private String city;
  
      @OneToMany(mappedBy = "venue", fetch = FetchType.EAGER)
      private Set&lt;ConcertEntity&gt; concerts = new HashSet&lt;&gt;();
  
      @Column(name = "VERSION")
      @Version
      private Long version;
  
      public Long getId() {
          return id;
      }
  
      public void setId(Long id) {
          this.id = id;
      }
  
      public String getImage() {
          return this.image;
      }
  
      public void setImage(String image) {
          this.image = image;
      }
  
      public String getName() {
          return name;
      }
  
      public void setName(String name) {
          this.name = name;
      }
  
      public Boolean getActive() {
          return active;
      }
  
      public void setActive(Boolean active) {
          this.active = active;
      }
  
      public String getCoordinates() {
          return coordinates;
      }
  
      public void setCoordinates(String coordinates) {
          this.coordinates = coordinates;
      }
  
      public Long getRating() {
          return rating;
      }
  
      public void setRating(Long rating) {
          this.rating = rating;
      }
  
      public String getCountry() {
          return country;
      }
  
      public void setCountry(String country) {
          this.country = country;
      }
  
      public String getCity() {
          return city;
      }
  
      public void setCity(String city) {
          this.city = city;
      }
  
      public Set&lt;ConcertEntity&gt; getConcerts() {
          return concerts;
      }
  
      public void setConcerts(Set&lt;ConcertEntity&gt; concerts) {
          this.concerts = concerts;
      }
  
      public Long getVersion() {
          return version;
      }
  
      public void setVersion(Long version) {
          this.version = version;
      }
  }
  </code></pre>
  
  <pre class="lang-java prettyprint-override"><code>package com.heatmanofurioso.gigger.service.persistencehibernateimplementation.entity;
  
  import javax.persistence.*;
  import java.time.LocalDateTime;
  import java.time.format.DateTimeFormatter;
  import java.util.HashSet;
  import java.util.Set;
  
  @Entity
  @Table(name = "CONCERT")
  public class ConcertEntity {
  
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      @Column(name = "ID", nullable = false)
      private Long id;
  
      @Column(name = "NAME", nullable = false)
      private String name;
  
      @Column(name = "DESCRIPTION")
      private String description;
  
      @Column(name = "RATING")
      private Long rating;
  
      @Column(name = "DATE", nullable = false)
      private String date;
  
      @Column(name = "IMAGE")
      private String image;
  
      @ManyToMany(fetch = FetchType.LAZY)
      @JoinTable(
          name = "USER_CONCERT",
          joinColumns = {@JoinColumn(name = "CONCERT_ID")},
          inverseJoinColumns = {@JoinColumn(name = "USER_ID")}
      )
      private Set&lt;UserEntity&gt; userConcert = new HashSet&lt;&gt;();
  
      @ManyToMany(fetch = FetchType.LAZY)
      @JoinTable(
          name = "CONCERT_ARTIST",
          joinColumns = {@JoinColumn(name = "CONCERT_ID")},
          inverseJoinColumns = {@JoinColumn(name = "ARTIST_ID")}
      )
      private Set&lt;ArtistEntity&gt; concertArtist = new HashSet&lt;&gt;();
  
      @OneToOne
      @JoinColumn(name = "FESTIVAL_ID", nullable = false)
      private FestivalEntity festival;
  
      @ManyToOne(fetch = FetchType.EAGER)
      @JoinColumn(name = "VENUE_ID")
      private VenueEntity venue;
  
      @Column(name = "VERSION")
      @Version
      private Long version;
  
      public Long getId() {
          return id;
      }
  
      public void setId(Long id) {
          this.id = id;
      }
  
      public String getName() {
          return name;
      }
  
      public void setName(String name) {
          this.name = name;
      }
  
      public String getDescription() {
          return description;
      }
  
      public void setDescription(String description) {
          this.description = description;
      }
  
      public Long getRating() {
          return rating;
      }
  
      public void setRating(Long rating) {
          this.rating = rating;
      }
  
      public LocalDateTime getDate() {
          DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
          return LocalDateTime.parse(date, formatter);
      }
  
      public void setDate(LocalDateTime date) {
          this.date = date.toString();
      }
  
      public String getDateString() {
          return date;
      }
  
      public void setDate(String date) {
          this.date = date;
      }
  
      public String getImage() {
          return image;
      }
  
      public void setImage(String image) {
          this.image = image;
      }
  
      public Set&lt;UserEntity&gt; getUserConcert() {
          return userConcert;
      }
  
      public void setUserConcert(Set&lt;UserEntity&gt; userConcert) {
          this.userConcert = userConcert;
      }
  
      public Set&lt;ArtistEntity&gt; getConcertArtist() {
          return concertArtist;
      }
  
      public void setConcertArtist(Set&lt;ArtistEntity&gt; concertArtist) {
          this.concertArtist = concertArtist;
      }
  
      public FestivalEntity getFestival() {
          return festival;
      }
  
      public void setFestival(FestivalEntity festival) {
          this.festival = festival;
      }
  
      public VenueEntity getVenue() {
          return venue;
      }
  
      public void setVenue(VenueEntity venue) {
          this.venue = venue;
      }
  
      public Long getVersion() {
          return version;
      }
  
      public void setVersion(Long version) {
          this.version = version;
      }
  }
  </code></pre>
  
  <p>The returned dataset corresponds to the following</p>
  
  <p>Now, my issue is that if I try to add the @Where annotation to my Concerts collection on my VenueEntity, like so</p>
  
  <pre class="lang-java prettyprint-override"><code>
  @OneToMany(mappedBy = "venue", fetch = FetchType.EAGER)
      private Set&lt;ConcertEntity&gt; concerts = new HashSet&lt;&gt;();
  
      @OneToMany(mappedBy = "venue", fetch = FetchType.EAGER)
      @Where(clause = "date &lt; current_date")
      private Set&lt;ConcertEntity&gt; pastConcerts = new HashSet&lt;&gt;();
  
      @OneToMany(mappedBy = "venue", fetch = FetchType.EAGER)
      @Where(clause = "date =&gt; current_date")
      private Set&lt;ConcertEntity&gt; futureConcerts = new HashSet&lt;&gt;();
  
  </code></pre>
  
  <p>those two collections return empty datasets, even though, at the creation of the rows on the database, I am setting the value of the <code>DATE</code> field as <code>current_date</code>, so the <code>pastConcerts</code> collection should show results at least</p>