Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 28th, 2012  |  syntax: None  |  size: 0.66 KB  |  hits: 19  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Filtering a collection using the @Filter hibernate annotation in java
  2. @FilterDefs()
  3. class A{
  4.  
  5. @OneToMany(mappedBy = "productType", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
  6. @Filter(name = "something", condition = "entityType = 'SKU1'")  
  7. Set<B> set1 = new HashSet<B>();
  8.  
  9. @OneToMany(mappedBy = "productType", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
  10. @Filter(name = "something", condition = "entityType = 'SKU2'")  
  11. Set<B> set2 = new HashSet<B>();
  12.  
  13.  }
  14.  
  15. class B{
  16.  
  17. @ManyToOne(cascade = CascadeType.ALL)
  18. private A productType;
  19.  
  20. @Column(name = "entity_type")
  21. @Enumerated(EnumType.STRING)
  22. private EntityType entityType;
  23. }
  24.        
  25. session.enableFilter("something");