Want more features on Pastebin? Sign Up, it's FREE!
Guest

UserAccount.java

By: a guest on Mar 10th, 2010  |  syntax: Java  |  size: 1.55 KB  |  views: 96  |  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 com.apress.timesheets.entity;
  2.  
  3. import static javax.persistence.CascadeType.PERSIST;
  4. import static javax.persistence.FetchType.LAZY;
  5.  
  6. import java.io.Serializable;
  7. import java.util.*;
  8.  
  9. import javax.persistence.*;
  10.  
  11. @Entity
  12. @NamedQueries( {
  13.       @NamedQuery(name = "getUserAccountByName",
  14.                query = "from UserAccount where accountName = :name"),
  15.       @NamedQuery(name = "listUserAccountByName",
  16.                query = "from UserAccount order by accountName")
  17. })
  18. public class UserAccount implements Serializable {
  19.    private static final long serialVersionUID = 0L;
  20.  
  21.    private Long id;
  22.    private String accountName;
  23.    private Set<UserRole> roles = new HashSet<UserRole>();
  24.  
  25.    public UserAccount() {
  26.    }
  27.  
  28.    public UserAccount(final String accountName) {
  29.       this.accountName = accountName;
  30.    }
  31.  
  32.    @Id
  33.    @GeneratedValue
  34.    public Long getId() {
  35.       return id;
  36.    }
  37.  
  38.    public void setId(final Long id) {
  39.       this.id = id;
  40.    }
  41.  
  42.    @ManyToMany(fetch = LAZY, cascade = PERSIST)
  43.    @JoinTable(name = "account_role",
  44.             joinColumns = { @JoinColumn(name = "user") },
  45.             inverseJoinColumns = { @JoinColumn(name = "role") })
  46.    public Set<UserRole> getRoles() {
  47.       return roles;
  48.    }
  49.  
  50.    public void setRoles(final Set<UserRole> roles) {
  51.       this.roles = roles;
  52.    }
  53.  
  54.    @Column(unique = true, nullable = false)
  55.    public String getAccountName() {
  56.       return accountName;
  57.    }
  58.  
  59.    public void setAccountName(String accountName) {
  60.       this.accountName = accountName;
  61.    }
  62. }
clone this paste RAW Paste Data