Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package services;
- import org.springframework.transaction.annotation.Transactional;
- import org.hibernate.Query;
- import org.hibernate.SessionFactory;
- import org.hibernate.Session;
- import data.*;
- import java.util.List;
- // This class is the business services tier in the application.
- // @Transactional is needed so that a Hibernate transaction is set up,
- // otherwise updates won't have an affect
- @Transactional
- public class Services {
- // So Spring can inject the session factory
- SessionFactory sessionFactory;
- public void setSessionFactory(SessionFactory value) {
- sessionFactory = value;
- }
- // Shortcut for sessionFactory.getCurrentSession()
- public Session sess() {
- return sessionFactory.getCurrentSession();
- }
- public Forms getFormsById(Long id) {
- return (Forms) sess().load(Forms.class, id);
- }
- @SuppressWarnings("unchecked")
- public List<Forms> getForms() {
- return sess().createQuery("from Forms").list();
- }
- @SuppressWarnings("unchecked")
- public List<Questions> getQuestions() {
- return sess().createQuery("from Questions").list();
- }
- public Questions getQuestionById(Long id) {
- return (Questions) sess().load(Questions.class, id);
- }
- @SuppressWarnings("unchecked")
- public List<Questions> getQuestionsByForm(Long formId) {
- // return (Questions) sess().load(Questions.class, formId);
- Query queryQuestion = sess().createQuery("from Questions where form_id = :formId");
- queryQuestion.setParameter("formId", formId);
- return queryQuestion.list();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment