title: Spring Data JPA: Specification with "like" and Long
body: <p>I have the following problem. 
  I used spring-data and i want to create a "like" statement for a Long Property.</p>
  
  <p>I have tried the following, but without success. </p>
  
  <pre><code>private Specification&lt;T&gt; createSpecification()
  {
      return new Specification&lt;T&gt;()
      {
  
          @Override
          public Predicate toPredicate(final Root&lt;T&gt; root, final CriteriaQuery&lt;?&gt; query, final CriteriaBuilder cb)
          {
  
              final Predicate like = query.where(cb.like(root.&lt;String&gt; get("kundenNr"), "%4%")).getRestriction();
  
              return like;
          }
      };
  
  }
  </code></pre>
  
  <p>and domain class</p>
  
  <pre><code>public class Kunde implements Serializable
  {
  
  @ColumnYB(lable = "KundenNr.", order = 1)
  @Id
  @javax.persistence.Column(nullable = false, name = "kundennr")
  protected Long kundenNr;
  
  @ColumnYB(lable = "Deaktiviert")
  @Column(nullable = false)
  private boolean deaktiviert = false;
  
  @Column(name = "kundenart")
  private String kundenart;
  ...
  </code></pre>
  
  <p>I get the following error. </p>
  
  <pre><code>org.springframework.dao.InvalidDataAccessApiUsageException: Parameter value [%4%] did not match expected type [java.lang.Long]; nested exception is java.lang.IllegalArgumentException: Parameter value [%4%] did not match expected type [java.lang.Long]
  at org.springframework.orm.jpa.EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(EntityManagerFactoryUtils.java:384) ~[spring-orm-4.0.1.RELEASE.jar:4.0.1.RELEASE]
  at org.springframework.orm.jpa.vendor.HibernateJpaDialect.translateExceptionIfPossible(HibernateJpaDialect.java:157) ~[spring-orm-4.0.1.RELEASE.jar:4.0.1.RELEASE]
  at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.translateExceptionIfPossible(AbstractEntityManagerFactoryBean.java:417) ~[spring-orm-4.0.1.RELEASE.jar:4.0.1.RELEASE]
  at org.springframework.dao.support.ChainedPersistenceExceptionTranslator.translateExceptionIfPossible(ChainedPersistenceExceptionTranslator.java:59) ~[spring-tx-4.0.1.RELEASE.jar:4.0.1.RELEASE]
  at org.springframework.dao.support.DataAccessUtils.translateIfNecessary(DataAccessUtils.java:213) ~[spring-tx-4.0.1.RELEASE.jar:4.0.1.RELEASE]
  at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:147) ~[spring-tx-4.0.1.RELEASE.jar:4.0.1.RELEASE]
  at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.0.1.RELEASE.jar:4.0.1.RELEASE]
  at org.springframework.data.jpa.repository.support.LockModeRepositoryPostProcessor$LockModePopulatingMethodIntercceptor.invoke(LockModeRepositoryPostProcessor.java:92) ~[spring-data-jpa-1.4.1.RELEASE.jar:na]
  at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.0.1.RELEASE.jar:4.0.1.RELEASE]
  at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92) ~[spring-aop-4.0.1.RELEASE.jar:4.0.1.RELEASE]
  at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.0.1.RELEASE.jar:4.0.1.RELEASE]
  </code></pre>
  
  <p>What am I doing wrong?</p>