Java tutorial
/** * "Visual Paradigm: DO NOT MODIFY THIS FILE!" * * This is an automatic generated file. It will be regenerated every time * you generate persistence class. * * Modifying its content may cause the program not work, or your work may lost. */ /** * Licensee: btwesigye * License Type: Purchased */ package entities; import org.orm.*; import org.hibernate.Query; import org.hibernate.LockMode; import java.util.List; import java.io.Serializable; import javax.persistence.*; @Entity @org.hibernate.annotations.Proxy(lazy = false) @Table(name = "division") public class Division implements Serializable { public Division() { } public static Division loadDivisionByORMID(int division_id) throws PersistentException { try { PersistentSession session = entities.EVotingPersistentManager.instance().getSession(); return loadDivisionByORMID(session, division_id); } catch (Exception e) { e.printStackTrace(); throw new PersistentException(e); } } public static Division getDivisionByORMID(int division_id) throws PersistentException { try { PersistentSession session = entities.EVotingPersistentManager.instance().getSession(); return getDivisionByORMID(session, division_id); } catch (Exception e) { e.printStackTrace(); throw new PersistentException(e); } } public static Division loadDivisionByORMID(int division_id, org.hibernate.LockMode lockMode) throws PersistentException { try { PersistentSession session = entities.EVotingPersistentManager.instance().getSession(); return loadDivisionByORMID(session, division_id, lockMode); } catch (Exception e) { e.printStackTrace(); throw new PersistentException(e); } } public static Division getDivisionByORMID(int division_id, org.hibernate.LockMode lockMode) throws PersistentException { try { PersistentSession session = entities.EVotingPersistentManager.instance().getSession(); return getDivisionByORMID(session, division_id, lockMode); } catch (Exception e) { e.printStackTrace(); throw new PersistentException(e); } } public static Division loadDivisionByORMID(PersistentSession session, int division_id) throws PersistentException { try { return (Division) session.load(entities.Division.class, new Integer(division_id)); } catch (Exception e) { e.printStackTrace(); throw new PersistentException(e); } } public static Division getDivisionByORMID(PersistentSession session, int division_id) throws PersistentException { try { return (Division) session.get(entities.Division.class, new Integer(division_id)); } catch (Exception e) { e.printStackTrace(); throw new PersistentException(e); } } public static Division loadDivisionByORMID(PersistentSession session, int division_id, org.hibernate.LockMode lockMode) throws PersistentException { try { return (Division) session.load(entities.Division.class, new Integer(division_id), lockMode); } catch (Exception e) { e.printStackTrace(); throw new PersistentException(e); } } public static Division getDivisionByORMID(PersistentSession session, int division_id, org.hibernate.LockMode lockMode) throws PersistentException { try { return (Division) session.get(entities.Division.class, new Integer(division_id), lockMode); } catch (Exception e) { e.printStackTrace(); throw new PersistentException(e); } } public static List queryDivision(String condition, String orderBy) throws PersistentException { try { PersistentSession session = entities.EVotingPersistentManager.instance().getSession(); return queryDivision(session, condition, orderBy); } catch (Exception e) { e.printStackTrace(); throw new PersistentException(e); } } public static List queryDivision(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException { try { PersistentSession session = entities.EVotingPersistentManager.instance().getSession(); return queryDivision(session, condition, orderBy, lockMode); } catch (Exception e) { e.printStackTrace(); throw new PersistentException(e); } } public static Division[] listDivisionByQuery(String condition, String orderBy) throws PersistentException { try { PersistentSession session = entities.EVotingPersistentManager.instance().getSession(); return listDivisionByQuery(session, condition, orderBy); } catch (Exception e) { e.printStackTrace(); throw new PersistentException(e); } } public static Division[] listDivisionByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException { try { PersistentSession session = entities.EVotingPersistentManager.instance().getSession(); return listDivisionByQuery(session, condition, orderBy, lockMode); } catch (Exception e) { e.printStackTrace(); throw new PersistentException(e); } } public static List queryDivision(PersistentSession session, String condition, String orderBy) throws PersistentException { StringBuffer sb = new StringBuffer("From entities.Division as Division"); if (condition != null) sb.append(" Where ").append(condition); if (orderBy != null) sb.append(" Order By ").append(orderBy); try { Query query = session.createQuery(sb.toString()); return query.list(); } catch (Exception e) { e.printStackTrace(); throw new PersistentException(e); } } public static List queryDivision(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException { StringBuffer sb = new StringBuffer("From entities.Division as Division"); if (condition != null) sb.append(" Where ").append(condition); if (orderBy != null) sb.append(" Order By ").append(orderBy); try { Query query = session.createQuery(sb.toString()); query.setLockMode("Division", lockMode); return query.list(); } catch (Exception e) { e.printStackTrace(); throw new PersistentException(e); } } public static Division[] listDivisionByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException { try { List list = queryDivision(session, condition, orderBy); return (Division[]) list.toArray(new Division[list.size()]); } catch (Exception e) { e.printStackTrace(); throw new PersistentException(e); } } public static Division[] listDivisionByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException { try { List list = queryDivision(session, condition, orderBy, lockMode); return (Division[]) list.toArray(new Division[list.size()]); } catch (Exception e) { e.printStackTrace(); throw new PersistentException(e); } } public static Division loadDivisionByQuery(String condition, String orderBy) throws PersistentException { try { PersistentSession session = entities.EVotingPersistentManager.instance().getSession(); return loadDivisionByQuery(session, condition, orderBy); } catch (Exception e) { e.printStackTrace(); throw new PersistentException(e); } } public static Division loadDivisionByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException { try { PersistentSession session = entities.EVotingPersistentManager.instance().getSession(); return loadDivisionByQuery(session, condition, orderBy, lockMode); } catch (Exception e) { e.printStackTrace(); throw new PersistentException(e); } } public static Division loadDivisionByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException { Division[] divisions = listDivisionByQuery(session, condition, orderBy); if (divisions != null && divisions.length > 0) return divisions[0]; else return null; } public static Division loadDivisionByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException { Division[] divisions = listDivisionByQuery(session, condition, orderBy, lockMode); if (divisions != null && divisions.length > 0) return divisions[0]; else return null; } public static java.util.Iterator iterateDivisionByQuery(String condition, String orderBy) throws PersistentException { try { PersistentSession session = entities.EVotingPersistentManager.instance().getSession(); return iterateDivisionByQuery(session, condition, orderBy); } catch (Exception e) { e.printStackTrace(); throw new PersistentException(e); } } public static java.util.Iterator iterateDivisionByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException { try { PersistentSession session = entities.EVotingPersistentManager.instance().getSession(); return iterateDivisionByQuery(session, condition, orderBy, lockMode); } catch (Exception e) { e.printStackTrace(); throw new PersistentException(e); } } public static java.util.Iterator iterateDivisionByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException { StringBuffer sb = new StringBuffer("From entities.Division as Division"); if (condition != null) sb.append(" Where ").append(condition); if (orderBy != null) sb.append(" Order By ").append(orderBy); try { Query query = session.createQuery(sb.toString()); return query.iterate(); } catch (Exception e) { e.printStackTrace(); throw new PersistentException(e); } } public static java.util.Iterator iterateDivisionByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException { StringBuffer sb = new StringBuffer("From entities.Division as Division"); if (condition != null) sb.append(" Where ").append(condition); if (orderBy != null) sb.append(" Order By ").append(orderBy); try { Query query = session.createQuery(sb.toString()); query.setLockMode("Division", lockMode); return query.iterate(); } catch (Exception e) { e.printStackTrace(); throw new PersistentException(e); } } public static Division loadDivisionByCriteria(DivisionCriteria divisionCriteria) { Division[] divisions = listDivisionByCriteria(divisionCriteria); if (divisions == null || divisions.length == 0) { return null; } return divisions[0]; } public static Division[] listDivisionByCriteria(DivisionCriteria divisionCriteria) { return divisionCriteria.listDivision(); } public static Division createDivision() { return new entities.Division(); } public boolean save() throws PersistentException { try { entities.EVotingPersistentManager.instance().saveObject(this); return true; } catch (Exception e) { e.printStackTrace(); throw new PersistentException(e); } } public boolean delete() throws PersistentException { try { entities.EVotingPersistentManager.instance().deleteObject(this); return true; } catch (Exception e) { e.printStackTrace(); throw new PersistentException(e); } } public boolean refresh() throws PersistentException { try { entities.EVotingPersistentManager.instance().getSession().refresh(this); return true; } catch (Exception e) { e.printStackTrace(); throw new PersistentException(e); } } public boolean evict() throws PersistentException { try { entities.EVotingPersistentManager.instance().getSession().evict(this); return true; } catch (Exception e) { e.printStackTrace(); throw new PersistentException(e); } } public boolean deleteAndDissociate() throws PersistentException { try { if (getDistrict() != null) { getDistrict().getDivision().remove(this); } entities.Post[] lPosts = (entities.Post[]) getPost().toArray(new entities.Post[getPost().size()]); for (int i = 0; i < lPosts.length; i++) { lPosts[i].setDivision(null); } return delete(); } catch (Exception e) { e.printStackTrace(); throw new PersistentException(e); } } public boolean deleteAndDissociate(org.orm.PersistentSession session) throws PersistentException { try { if (getDistrict() != null) { getDistrict().getDivision().remove(this); } entities.Post[] lPosts = (entities.Post[]) getPost().toArray(new entities.Post[getPost().size()]); for (int i = 0; i < lPosts.length; i++) { lPosts[i].setDivision(null); } try { session.delete(this); return true; } catch (Exception e) { return false; } } catch (Exception e) { e.printStackTrace(); throw new PersistentException(e); } } @Column(name = "division_id", nullable = false, length = 10) @Id @GeneratedValue(generator = "ENTITIES_DIVISION_DIVISION_ID_GENERATOR") @org.hibernate.annotations.GenericGenerator(name = "ENTITIES_DIVISION_DIVISION_ID_GENERATOR", strategy = "native") private int division_id; @Column(name = "division_name", nullable = true, length = 100) private String division_name; @ManyToOne(targetEntity = entities.District.class, fetch = FetchType.LAZY) @org.hibernate.annotations.Cascade({ org.hibernate.annotations.CascadeType.LOCK }) @JoinColumns({ @JoinColumn(name = "district_id", referencedColumnName = "district_id", nullable = false) }) private entities.District district; @Column(name = "is_deleted", nullable = true, length = 1) private Integer is_deleted; @Column(name = "is_active", nullable = false, length = 1) private int is_active; @Column(name = "add_date", nullable = true) private java.sql.Timestamp add_date; @Column(name = "add_by", nullable = true, length = 11) private Integer add_by; @Column(name = "last_edit_date", nullable = true) private java.sql.Timestamp last_edit_date; @Column(name = "last_edit_by", nullable = true, length = 11) private Integer last_edit_by; @OneToMany(mappedBy = "division", targetEntity = entities.Post.class) @org.hibernate.annotations.Cascade({ org.hibernate.annotations.CascadeType.SAVE_UPDATE, org.hibernate.annotations.CascadeType.LOCK }) @org.hibernate.annotations.LazyCollection(org.hibernate.annotations.LazyCollectionOption.EXTRA) private java.util.Set post = new java.util.HashSet(); private void setDivision_id(int value) { this.division_id = value; } public int getDivision_id() { return division_id; } public int getORMID() { return getDivision_id(); } public void setDivision_name(String value) { this.division_name = value; } public String getDivision_name() { return division_name; } public void setIs_deleted(int value) { setIs_deleted(new Integer(value)); } public void setIs_deleted(Integer value) { this.is_deleted = value; } public Integer getIs_deleted() { return is_deleted; } public void setIs_active(int value) { this.is_active = value; } public int getIs_active() { return is_active; } public void setAdd_date(java.sql.Timestamp value) { this.add_date = value; } public java.sql.Timestamp getAdd_date() { return add_date; } public void setAdd_by(int value) { setAdd_by(new Integer(value)); } public void setAdd_by(Integer value) { this.add_by = value; } public Integer getAdd_by() { return add_by; } public void setLast_edit_date(java.sql.Timestamp value) { this.last_edit_date = value; } public java.sql.Timestamp getLast_edit_date() { return last_edit_date; } public void setLast_edit_by(int value) { setLast_edit_by(new Integer(value)); } public void setLast_edit_by(Integer value) { this.last_edit_by = value; } public Integer getLast_edit_by() { return last_edit_by; } public void setDistrict(entities.District value) { this.district = value; } public entities.District getDistrict() { return district; } public void setPost(java.util.Set value) { this.post = value; } public java.util.Set getPost() { return post; } public String toString() { return String.valueOf(getDivision_id()); } }