daily pastebin goal
36%
SHARE
TWEET

Untitled

a guest Aug 10th, 2018 53 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. iterating through a collection in JPQL
  2. @Entity
  3. public class Article implements Serializable {
  4.  
  5.    @Basic(optional = false)
  6.    @NotNull
  7.    @Lob
  8.    @Size(min = 1, max = 65535)
  9.    @Column(name = "body", nullable = false, length = 65535)
  10.    private String body;
  11.    @Basic(optional = false)
  12.  
  13.    @NotNull
  14.    @Size(min = 1, max = 250)
  15.    @Column(name = "title", nullable = false, length = 250)
  16.    private String title;
  17.  
  18.    @Basic(optional = false)
  19.    @NotNull
  20.    @Size(min = 1, max = 9)
  21.    @Column(name = "status", nullable = false, length = 9)
  22.    private String status;
  23.  
  24.    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
  25.    @JoinColumn(name = "articleId", referencedColumnName = "id", nullable = false)
  26.    private List<Tag> tagList;
  27.  
  28.    // other attributes and methods
  29. }
  30.    
  31. SELECT DISTINCT a FROM Article a ,IN(a.tagList) tag
  32.             WHERE a.status = :status AND
  33.             (a.title LIKE :pattern OR a.body LIKE :pattern
  34.             OR tag.name LIKE :pattern)
  35.    
  36. select distinct a from Article a left join a.tagList tag where a.status = :status and
  37. (a.title like :pattern or a.body like :pattern or tag.name like :pattern)
  38.    
  39. select a from Article a join a.tagList tag where a.status = :status and
  40.     (a.title like :pattern or a.body like :pattern or tag.name like :pattern)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top