Methods Summary |
---|
public static void | delete(java.lang.Object o)Deletes any persistable object from the database.
Session s = null;
try {
s = getSession();
s.delete(o);
s.flush();
s.connection().commit();
} catch (Exception ex) {
ex.printStackTrace();
} finally {
s.close();
}
|
public static java.util.List | getClasses()Loads all UniversityClasses in the database.
Session s = null;
List results = null;
try {
s = getSession();
results = s.createCriteria(UniversityClass.class).list();
} catch (Exception ex) {
ex.printStackTrace();
} finally {
s.close();
}
return results;
|
public static Department | getDepartment(java.lang.Long id)Simple department load.
Session s = null;
Department d = null;
try {
s = getSession();
d = (Department)s.load(Department.class, id);
} catch (Exception ex) {
ex.printStackTrace();
} finally {
s.close();
}
return d;
|
public static java.util.List | getPeople()Only useful when using the polymorphic mappings. Loads all implementations of the Person
interface, regardless of concrete type. All items returned retain full type fidelity;
Professors can be cast to Person or Professor, Students to Person or Student.
Session s = null;
List results = null;
try {
s = getSession();
results = s.createCriteria(Person.class).list();
} catch (Exception ex) {
ex.printStackTrace();
} finally {
s.close();
}
return results;
|
public static java.util.List | getPeopleNames()Uses an HQL query to return a List of Arrays, each one containing the first and last names of a Person.
Session s = null;
List results = null;
try {
s = getSession();
results = s.createQuery("SELECT person.firstName, person.lastName FROM Person person").list();
} catch (Exception ex) {
ex.printStackTrace();
} finally {
s.close();
}
return results;
|
public static Professor | getProfessor(java.lang.Long id)Load a Professor object. When using the polymorphic mappings, this will only load
rows that match the Professor's discriminator value, no matter what ID you give it.
Session s = null;
Professor result = null;
try {
s = getSession();
result = (Professor)s.load(Professor.class, id);
} catch (Exception ex) {
ex.printStackTrace();
} finally {
s.close();
}
return result;
|
public static Professor | getProfessorWithEmails(java.lang.Long id)Eagerly initializes the otherwise lazily loaded emails collection of Professor
before returning it.
Session s = null;
Professor result = null;
try {
s = getSession();
result = (Professor)s.load(Professor.class, id);
Hibernate.initialize(result.getEmails());
} catch (Exception ex) {
ex.printStackTrace();
} finally {
s.close();
}
return result;
|
public static java.util.List | getProfessors()Returns a List of all Professors in the database. If you are
using the polymorphic mapping, it will distinguish between
Professors and Students.
Session s = null;
List results = null;
try {
s = getSession();
results = s.createCriteria(Professor.class).list();
} catch (Exception ex) {
ex.printStackTrace();
} finally {
s.close();
}
return results;
|
public static java.util.List | getProfessorsByDegree(java.lang.String degree)Uses HQL paramaterized query to select a subset of available Professors.
Session s = null;
List results = null;
try {
s = getSession();
Query q = s.createQuery("from Professor where degree = :degree");
q.setString("degree", degree);
results = q.list();
} catch (Exception ex) {
ex.printStackTrace();
} finally {
s.close();
}
return results;
|
private static org.hibernate.Session | getSession()Utility method for getting an open Session. This allows a central entry point
for adding Interceptors or Connections to the Session.
Configuration config = new Configuration();
config.configure();
config.addClass(UniversityClass.class);
config.addClass(Syllabus.class);
config.addClass(Person.class);
config.addClass(Department.class);
factory = config.buildSessionFactory();
return factory.openSession();
|
public static Student | getStudent(java.lang.Long id)Loads a Student, and eagerly initializes the UniversityClass collection.
Session s = null;
Student result = null;
try {
s = getSession();
result = (Student)s.load(Student.class, id);
Hibernate.initialize(result.getClasses());
} catch (Exception ex) {
ex.printStackTrace();
} finally {
s.close();
}
return result;
|
public static java.util.List | getStudents()Loads all Studnets in the database. When using the polymorphic mapping,
this will distinguish between Professors and Students.
Session s = null;
List results = null;
try {
s = getSession();
results = s.createCriteria(Student.class).list();
} catch (Exception ex) {
ex.printStackTrace();
} finally {
s.close();
}
return results;
|
public static Syllabus | getSyllabus(java.lang.Long id)Loads a Syllabus and eagerly initializes the UniversityClass relationship.
Session s = null;
Syllabus result = null;
try {
s = getSession();
result = (Syllabus)s.load(Syllabus.class, id);
Hibernate.initialize(result.getUclass());
} catch (Exception ex) {
ex.printStackTrace();
} finally {
s.close();
}
return result;
|
public static UniversityClass | getUClass(java.lang.Long id)Loads a UniversityClass and eagerly initializes the Syllabus relationship.
Session s = null;
UniversityClass result = null;
try {
s = getSession();
result = (UniversityClass)s.load(UniversityClass.class, id);
Hibernate.initialize(result.getSyllabus());
} catch (Exception ex) {
ex.printStackTrace();
} finally {
s.close();
}
return result;
|
public static void | save(java.lang.Object o)Takes any persistable object and saves it to the db, using the
indiscriminate saveOrUpdate method, which will either create new records
or update existing records according to the object being saved.
Session s = null;
try {
s = getSession();
s.saveOrUpdate(o);
s.flush();
s.connection().commit();
} catch (Exception ex) {
ex.printStackTrace();
} finally {
s.close();
}
|