title: How to map java enum to postgreSQL enum for conditional select query
body: <p>I am using PostgreSQL and java for building the backend of an application.</p>
  <p>In PostgreSQL, I have used an enum here.</p>
  <p><a href="https://i.stack.imgur.com/kaMrQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/kaMrQ.png" alt="enter image description here" /></a></p>
  <p>and in java I have used enum for layer variable also.</p>
  <pre><code>     @Entity
       @Getter
       @Setter
       @Table(name = &quot;usecase_details&quot;)
       @JsonIgnoreProperties
       public class UsecaseDetails {
       @Id
       @Column(name=&quot;id&quot;, nullable = false)
       @SequenceGenerator(name= &quot;usecase_details_sequence&quot;, sequenceName 
       =&quot;usecase_details_id_sequence&quot;)
      @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = 
       &quot;usecase_details_sequence&quot; )
  private Long id;
  @Column(columnDefinition = &quot;layer_t&quot;, nullable = false)
  @Enumerated(EnumType.STRING)
  @Type(type = &quot;com.apple.exampleportal.portal.utility.EnumTypePostgreSql&quot;)
  private Layer layer;
  private Long check_id;
  private int usecase_id;
  private String description;
  private String fix_type;
  private String radars;
  private boolean show_usecase = true;
  
  
  public UsecaseDetails(Long id, Layer layer, Long check_id, int usecase_id, String description, String fix_type, String radars, boolean show_usecase) {
      this.id = id;
      this.layer = layer;
      this.check_id = check_id;
      this.usecase_id = usecase_id;
      this.description = description;
      this.fix_type = fix_type;
      this.radars = radars;
      this.show_usecase = show_usecase;
  }
  // skipping getter setter for brevity
  </code></pre>
  <p>EnumTypePostgreSql. class is</p>
  <pre><code>   public class EnumTypePostgreSql extends EnumType {
  
  @Override
  public void nullSafeSet(
          PreparedStatement st,
          Object value,
          int index,
          SharedSessionContractImplementor session)
          throws HibernateException, SQLException {
      st.setObject(
              index,
              value != null ?
                      ((Enum) value).name() :
                      null,
              Types.OTHER
      );
  }
   }
  </code></pre>
  <p>and my custom queries are as follows:</p>
  <pre><code>   public interface UsecaseRepository extends JpaRepository&lt;UsecaseDetails, Long&gt; {
  
  
  @Query(value = &quot;SELECT  description, fix_type, usecase_id, layer FROM public.usecase_details WHERE layer = :layer&quot;, nativeQuery = true)
  List&lt;UsecaseDetails&gt; findUsecaseByLayer(Layer layer);
  
  @Query(value = &quot;INSERT INTO public.usecase_details(description,fix_type, usecase_id,  layer)\n&quot;+
          &quot;\tVALUES (?,?,?,?)&quot;, nativeQuery = true)
  UsecaseDetails insertDetails(UsecaseDetails usecaseDetails);
  </code></pre>
  <p>The insert query is working properly but for findUsecaseByLayer , I am getting the following error.
  <a href="https://i.stack.imgur.com/1eZ8Z.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1eZ8Z.png" alt="enter image description here" /></a></p>
  <p>I am unable to detect my mistake. Please help!</p>