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 = "polling_station") public class Polling_station implements Serializable { public Polling_station() { } public static Polling_station loadPolling_stationByORMID(int polling_station_id) throws PersistentException { try { PersistentSession session = entities.EVotingPersistentManager.instance().getSession(); return loadPolling_stationByORMID(session, polling_station_id); } catch (Exception e) { e.printStackTrace(); throw new PersistentException(e); } } public static Polling_station getPolling_stationByORMID(int polling_station_id) throws PersistentException { try { PersistentSession session = entities.EVotingPersistentManager.instance().getSession(); return getPolling_stationByORMID(session, polling_station_id); } catch (Exception e) { e.printStackTrace(); throw new PersistentException(e); } } public static Polling_station loadPolling_stationByORMID(int polling_station_id, org.hibernate.LockMode lockMode) throws PersistentException { try { PersistentSession session = entities.EVotingPersistentManager.instance().getSession(); return loadPolling_stationByORMID(session, polling_station_id, lockMode); } catch (Exception e) { e.printStackTrace(); throw new PersistentException(e); } } public static Polling_station getPolling_stationByORMID(int polling_station_id, org.hibernate.LockMode lockMode) throws PersistentException { try { PersistentSession session = entities.EVotingPersistentManager.instance().getSession(); return getPolling_stationByORMID(session, polling_station_id, lockMode); } catch (Exception e) { e.printStackTrace(); throw new PersistentException(e); } } public static Polling_station loadPolling_stationByORMID(PersistentSession session, int polling_station_id) throws PersistentException { try { return (Polling_station) session.load(entities.Polling_station.class, new Integer(polling_station_id)); } catch (Exception e) { e.printStackTrace(); throw new PersistentException(e); } } public static Polling_station getPolling_stationByORMID(PersistentSession session, int polling_station_id) throws PersistentException { try { return (Polling_station) session.get(entities.Polling_station.class, new Integer(polling_station_id)); } catch (Exception e) { e.printStackTrace(); throw new PersistentException(e); } } public static Polling_station loadPolling_stationByORMID(PersistentSession session, int polling_station_id, org.hibernate.LockMode lockMode) throws PersistentException { try { return (Polling_station) session.load(entities.Polling_station.class, new Integer(polling_station_id), lockMode); } catch (Exception e) { e.printStackTrace(); throw new PersistentException(e); } } public static Polling_station getPolling_stationByORMID(PersistentSession session, int polling_station_id, org.hibernate.LockMode lockMode) throws PersistentException { try { return (Polling_station) session.get(entities.Polling_station.class, new Integer(polling_station_id), lockMode); } catch (Exception e) { e.printStackTrace(); throw new PersistentException(e); } } public static List queryPolling_station(String condition, String orderBy) throws PersistentException { try { PersistentSession session = entities.EVotingPersistentManager.instance().getSession(); return queryPolling_station(session, condition, orderBy); } catch (Exception e) { e.printStackTrace(); throw new PersistentException(e); } } public static List queryPolling_station(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException { try { PersistentSession session = entities.EVotingPersistentManager.instance().getSession(); return queryPolling_station(session, condition, orderBy, lockMode); } catch (Exception e) { e.printStackTrace(); throw new PersistentException(e); } } public static Polling_station[] listPolling_stationByQuery(String condition, String orderBy) throws PersistentException { try { PersistentSession session = entities.EVotingPersistentManager.instance().getSession(); return listPolling_stationByQuery(session, condition, orderBy); } catch (Exception e) { e.printStackTrace(); throw new PersistentException(e); } } public static Polling_station[] listPolling_stationByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException { try { PersistentSession session = entities.EVotingPersistentManager.instance().getSession(); return listPolling_stationByQuery(session, condition, orderBy, lockMode); } catch (Exception e) { e.printStackTrace(); throw new PersistentException(e); } } public static List queryPolling_station(PersistentSession session, String condition, String orderBy) throws PersistentException { StringBuffer sb = new StringBuffer("From entities.Polling_station as Polling_station"); 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 queryPolling_station(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException { StringBuffer sb = new StringBuffer("From entities.Polling_station as Polling_station"); 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("Polling_station", lockMode); return query.list(); } catch (Exception e) { e.printStackTrace(); throw new PersistentException(e); } } public static Polling_station[] listPolling_stationByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException { try { List list = queryPolling_station(session, condition, orderBy); return (Polling_station[]) list.toArray(new Polling_station[list.size()]); } catch (Exception e) { e.printStackTrace(); throw new PersistentException(e); } } public static Polling_station[] listPolling_stationByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException { try { List list = queryPolling_station(session, condition, orderBy, lockMode); return (Polling_station[]) list.toArray(new Polling_station[list.size()]); } catch (Exception e) { e.printStackTrace(); throw new PersistentException(e); } } public static Polling_station loadPolling_stationByQuery(String condition, String orderBy) throws PersistentException { try { PersistentSession session = entities.EVotingPersistentManager.instance().getSession(); return loadPolling_stationByQuery(session, condition, orderBy); } catch (Exception e) { e.printStackTrace(); throw new PersistentException(e); } } public static Polling_station loadPolling_stationByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException { try { PersistentSession session = entities.EVotingPersistentManager.instance().getSession(); return loadPolling_stationByQuery(session, condition, orderBy, lockMode); } catch (Exception e) { e.printStackTrace(); throw new PersistentException(e); } } public static Polling_station loadPolling_stationByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException { Polling_station[] polling_stations = listPolling_stationByQuery(session, condition, orderBy); if (polling_stations != null && polling_stations.length > 0) return polling_stations[0]; else return null; } public static Polling_station loadPolling_stationByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException { Polling_station[] polling_stations = listPolling_stationByQuery(session, condition, orderBy, lockMode); if (polling_stations != null && polling_stations.length > 0) return polling_stations[0]; else return null; } public static java.util.Iterator iteratePolling_stationByQuery(String condition, String orderBy) throws PersistentException { try { PersistentSession session = entities.EVotingPersistentManager.instance().getSession(); return iteratePolling_stationByQuery(session, condition, orderBy); } catch (Exception e) { e.printStackTrace(); throw new PersistentException(e); } } public static java.util.Iterator iteratePolling_stationByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException { try { PersistentSession session = entities.EVotingPersistentManager.instance().getSession(); return iteratePolling_stationByQuery(session, condition, orderBy, lockMode); } catch (Exception e) { e.printStackTrace(); throw new PersistentException(e); } } public static java.util.Iterator iteratePolling_stationByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException { StringBuffer sb = new StringBuffer("From entities.Polling_station as Polling_station"); 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 iteratePolling_stationByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException { StringBuffer sb = new StringBuffer("From entities.Polling_station as Polling_station"); 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("Polling_station", lockMode); return query.iterate(); } catch (Exception e) { e.printStackTrace(); throw new PersistentException(e); } } public static Polling_station loadPolling_stationByCriteria(Polling_stationCriteria polling_stationCriteria) { Polling_station[] polling_stations = listPolling_stationByCriteria(polling_stationCriteria); if (polling_stations == null || polling_stations.length == 0) { return null; } return polling_stations[0]; } public static Polling_station[] listPolling_stationByCriteria(Polling_stationCriteria polling_stationCriteria) { return polling_stationCriteria.listPolling_station(); } public static Polling_station createPolling_station() { return new entities.Polling_station(); } 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 (getVillage() != null) { getVillage().getPolling_station().remove(this); } entities.Voter[] lVoters = (entities.Voter[]) getVoter().toArray(new entities.Voter[getVoter().size()]); for (int i = 0; i < lVoters.length; i++) { lVoters[i].setPolling_station(null); } return delete(); } catch (Exception e) { e.printStackTrace(); throw new PersistentException(e); } } public boolean deleteAndDissociate(org.orm.PersistentSession session) throws PersistentException { try { if (getVillage() != null) { getVillage().getPolling_station().remove(this); } entities.Voter[] lVoters = (entities.Voter[]) getVoter().toArray(new entities.Voter[getVoter().size()]); for (int i = 0; i < lVoters.length; i++) { lVoters[i].setPolling_station(null); } try { session.delete(this); return true; } catch (Exception e) { return false; } } catch (Exception e) { e.printStackTrace(); throw new PersistentException(e); } } @Column(name = "polling_station_id", nullable = false, length = 10) @Id @GeneratedValue(generator = "ENTITIES_POLLING_STATION_POLLING_STATION_ID_GENERATOR") @org.hibernate.annotations.GenericGenerator(name = "ENTITIES_POLLING_STATION_POLLING_STATION_ID_GENERATOR", strategy = "native") private int polling_station_id; @Column(name = "poll_station_name", nullable = false, length = 50) private String poll_station_name; @ManyToOne(targetEntity = entities.Village.class, fetch = FetchType.LAZY) @org.hibernate.annotations.Cascade({ org.hibernate.annotations.CascadeType.LOCK }) @JoinColumns({ @JoinColumn(name = "village_id", referencedColumnName = "village_id", nullable = false) }) private entities.Village village; @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 = "polling_station", targetEntity = entities.Voter.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 voter = new java.util.HashSet(); private void setPolling_station_id(int value) { this.polling_station_id = value; } public int getPolling_station_id() { return polling_station_id; } public int getORMID() { return getPolling_station_id(); } public void setPoll_station_name(String value) { this.poll_station_name = value; } public String getPoll_station_name() { return poll_station_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 setVillage(entities.Village value) { this.village = value; } public entities.Village getVillage() { return village; } public void setVoter(java.util.Set value) { this.voter = value; } public java.util.Set getVoter() { return voter; } public String toString() { return String.valueOf(getPolling_station_id()); } }