ну там просто через анотации все. вот класс:
| Код | /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package tables;
import java.io.Serializable; import java.math.BigInteger; import java.util.Date; import java.util.Collection; import javax.persistence.*; import javax.validation.constraints.NotNull; import javax.validation.constraints.Size; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlTransient;
/** * * @author root */ @Entity @Table(name = "users", catalog = "otava", schema = "public") @XmlRootElement public class Users implements Serializable { private static final long serialVersionUID = 1L; @Id @Basic(optional = false) @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "user_id") private Integer userId; @Column(name = "group_id") private BigInteger groupId; @Column(name = "category_id") private BigInteger categoryId; @Basic(optional = false) @Column(name = "create_date") //@Temporal(TemporalType.TIMESTAMP) private String createDate; @Basic(optional = false) @NotNull @Column(name = "ls", nullable = false) private long ls; @Size(max = 16) @Column(name = "ustr", length = 16) private String ustr; @Size(max = 16) @Column(name = "fio", length = 16) private String fio; @Size(max = 256) @Column(name = "description", length = 256) private String description; @Basic(optional = false) @NotNull @Column(name = "locked", nullable = false) private boolean locked; @Column(name = "lock_date") @Temporal(TemporalType.TIMESTAMP) private Date lockDate; @OneToMany(mappedBy = "userId") private Collection<Logins> loginsCollection;
public Users() { }
public Users(Integer userId) { this.userId = userId; }
public Users(Integer userId, String createDate, long ls, boolean locked) { this.userId = userId; this.createDate = createDate; this.ls = ls; this.locked = locked; }
public Integer getUserId() { return userId; }
public void setUserId(Integer userId) { this.userId = userId; }
public BigInteger getGroupId() { return groupId; }
public void setGroupId(BigInteger groupId) { this.groupId = groupId; }
public BigInteger getCategoryId() { return categoryId; }
public void setCategoryId(BigInteger categoryId) { this.categoryId = categoryId; }
public String getCreateDate() { return createDate; }
public void setCreateDate(String createDate) { this.createDate = createDate; }
public long getLs() { return ls; }
public void setLs(long ls) { this.ls = ls; }
public String getUstr() { return ustr; }
public void setUstr(String ustr) { this.ustr = ustr; }
public String getFio() { return fio; }
public void setFio(String fio) { this.fio = fio; }
public String getDescription() { return description; }
public void setDescription(String description) { this.description = description; }
public boolean getLocked() { return locked; }
public void setLocked(boolean locked) { this.locked = locked; }
public Date getLockDate() { return lockDate; }
public void setLockDate(Date lockDate) { this.lockDate = lockDate; }
@XmlTransient public Collection<Logins> getLoginsCollection() { return loginsCollection; }
public void setLoginsCollection(Collection<Logins> loginsCollection) { this.loginsCollection = loginsCollection; }
@Override public int hashCode() { int hash = 0; hash += (userId != null ? userId.hashCode() : 0); return hash; }
@Override public boolean equals(Object object) { // TODO: Warning - this method won't work in the case the id fields are not set if (!(object instanceof Users)) { return false; } Users other = (Users) object; if ((this.userId == null && other.userId != null) || (this.userId != null && !this.userId.equals(other.userId))) { return false; } return true; }
@Override public String toString() { return "tables.Users[ userId=" + userId + " ]"; } }
|
А вот как вывожу данные:
| Код | /** * Операция веб-службы */ @WebMethod(operationName = "GetAllUser_XML") public List<Users> GetAllUser_XML() throws Exception { Session ses = NewHibernateUtil.getSessionFactory().getCurrentSession(); List<Users> ww = new ArrayList<Users>();
try { ses.beginTransaction(); ww = ses.createCriteria(Users.class).list(); return ww; } catch (Exception ex) { throw ex; } finally { ses.close(); } }
|
|