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

Untitled

By: a guest on Jan 29th, 2012  |  syntax: Groovy  |  size: 2.71 KB  |  hits: 88  |  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. package basis.domain
  2.  
  3. import javax.persistence.Id
  4. import javax.persistence.GeneratedValue
  5. import javax.persistence.Column
  6. import javax.persistence.Version
  7. import javax.validation.constraints.NotNull
  8. import javax.validation.constraints.Size
  9. import javax.persistence.GenerationType
  10. import org.apache.commons.lang3.builder.ToStringBuilder
  11. import org.apache.commons.lang3.builder.ToStringStyle
  12. import org.apache.commons.lang3.builder.HashCodeBuilder
  13. import org.apache.commons.lang3.builder.EqualsBuilder
  14. import javax.persistence.Entity
  15. import javax.persistence.Table
  16. import javax.persistence.NamedQueries
  17. import javax.persistence.NamedQuery
  18. import javax.xml.bind.annotation.XmlRootElement
  19.  
  20. /**
  21.  * @author Khaled.Noordin
  22.  */
  23. @Entity
  24. @Table(name = "property")
  25. // this section cause problems
  26. @NamedQueries(
  27. value = [
  28. @NamedQuery(name = Property.FIND_BY_KEY, query = "select p from Property p where p.key = :key"),
  29. @NamedQuery(name = Property.FIND_BY_VALUE, query = "select p from Property p where p.value = :value"),
  30. @NamedQuery(name = Property.FIND_BY_VALUELIKE, query = "select p from Property p where p.value like :value"),
  31. @NamedQuery(name = Property.FIND_BY_KEYLIKE, query = "select p from Property p where p.key like :key")
  32. ])
  33. // what can I do to get it fixed
  34. @XmlRootElement
  35. class Property implements Serializable {
  36.     static final String FIND_BY_KEY = "Property.findByKey"
  37.     static final String FIND_BY_VALUE = "Property.findByValue"
  38.     static final String FIND_BY_KEYLIKE = "Property.findByKeyLike"
  39.     static final String FIND_BY_VALUELIKE = "Property.findByValueLike"
  40.     @Id
  41.     @GeneratedValue(strategy = GenerationType.AUTO)
  42.     @Column(name = "property_id")
  43.     Long id;
  44.     @Version
  45.     Integer version;
  46.     @Column(name = "property_key", unique = true)
  47.     @Size(min = 2, max = 128)
  48.     @NotNull
  49.     String key;
  50.     @Column(name = "property_value")
  51.     @Size(max = 1024, min = 1)
  52.     @NotNull
  53.     String value;
  54.  
  55.     Property() {
  56.         id = null;
  57.         version = null;
  58.         key = null;
  59.         value = null;
  60.     }
  61.  
  62.     Property(String key) {
  63.         this();
  64.         this.key = key;
  65.     }
  66.  
  67.     Property(String key, String value) {
  68.         this(key);
  69.         this.value = value;
  70.     }
  71.  
  72.     @Override
  73.     String toString() {
  74.         return ToStringBuilder.reflectionToString(
  75.                 this,
  76.                 ToStringStyle.SHORT_PREFIX_STYLE)
  77.     }
  78.  
  79.     @Override
  80.     int hashCode() {
  81.         return HashCodeBuilder.reflectionHashCode(this, ["id", "version"])
  82.     }
  83.  
  84.     @Override
  85.     boolean equals(Object object) {
  86.         return (!(object instanceof Property) || object == null) ? false : EqualsBuilder.reflectionEquals(this, object, ["id", "version"])
  87.     }
  88. }