List of usage examples for org.hibernate SQLQuery addEntity
SQLQuery<T> addEntity(Class entityType);
From source file:com.sistcontable.dao.UsuarioDAO.java
public void searchUserByID(String id) { Session session = HibernateUtil.getSessionFactory().getCurrentSession(); session.beginTransaction();/*from ww w . j av a2 s. c o m*/ List<Usuario> lista = new ArrayList(); try { String query = "select * from usuario where id_usuario=:id_usuario"; SQLQuery sqlQuery = session.createSQLQuery(query); sqlQuery.addEntity(Usuario.class); sqlQuery.setParameter("id_usuario", id); //lista=sqlQuery.list(); List result = sqlQuery.list(); for (int i = 0; i < result.size(); i++) { System.out.println("id: "); Usuario usuario = (Usuario) result.get(i); System.out.println("id_usuario: " + usuario.getId_usuario()); System.out.println("id_persona: " + usuario.getId_persona()); System.out.println("nombre_usuario: " + usuario.getNombre_usuario()); System.out.println("clave: " + usuario.getClave()); } } catch (Exception e) { System.out.println("ERROR " + e); lista = null; } finally { session.close(); } }
From source file:com.sistcontable.dao.UsuarioDAO.java
public List<Usuario> searchAllUser() { Session session = HibernateUtil.getSessionFactory().getCurrentSession(); session.beginTransaction();//from w ww .j a v a 2s. c om List<Usuario> lista = new ArrayList(); try { String query = "select * from usuario"; SQLQuery sqlQuery = session.createSQLQuery(query); sqlQuery.addEntity(Usuario.class); lista = sqlQuery.list(); } catch (Exception e) { System.out.println("ERROR " + e); lista = null; } finally { session.close(); } return lista; }
From source file:com.thoughtworks.go.server.persistence.MaterialRepository.java
License:Apache License
@SuppressWarnings({ "unchecked" }) public List<Modification> getModificationsForPipelineRange(final String pipelineName, final Integer fromCounter, final Integer toCounter) { return (List<Modification>) getHibernateTemplate().execute((HibernateCallback) session -> { final List<Long> fromInclusiveModificationList = fromInclusiveModificationsForPipelineRange(session, pipelineName, fromCounter, toCounter); final Set<Long> fromModifications = new TreeSet<>( fromInclusiveModificationsForPipelineRange(session, pipelineName, fromCounter, fromCounter)); final Set<Long> fromExclusiveModificationList = new HashSet<>(); for (Long modification : fromInclusiveModificationList) { if (fromModifications.contains(modification)) { fromModifications.remove(modification); } else { fromExclusiveModificationList.add(modification); }// ww w .jav a 2s. com } SQLQuery query = session.createSQLQuery( "SELECT * FROM modifications WHERE id IN (:ids) ORDER BY materialId ASC, id DESC"); query.addEntity(Modification.class); query.setParameterList("ids", fromExclusiveModificationList.isEmpty() ? fromInclusiveModificationList : fromExclusiveModificationList); return query.list(); }); }
From source file:com.tysanclan.site.projectewok.util.forum.MemberForumViewContext.java
License:Open Source License
@Override public List<ForumCategory> getCategories(Session sess, User viewer, long offset, long count) { StringBuilder q = new StringBuilder(); q.append("SELECT * FROM FORUMCATEGORY FC "); q.append("WHERE EXISTS ("); q.append("SELECT * FROM FORUM f "); q.append(/*from w w w . ja v a 2s . c o m*/ "WHERE (f.DTYPE!='GroupForum' OR f.group_id IN (SELECT group_id FROM groupmembers WHERE user_id = :viewer)) AND f.category_id = FC.id"); q.append(") ORDER BY id ASC LIMIT :count OFFSET :offset"); SQLQuery query = sess.createSQLQuery(q.toString()); query.setLong("count", count); query.setLong("offset", offset); query.setLong("viewer", viewer.getId()); query.addEntity(ForumCategory.class); return listOf(query); }
From source file:com.tysanclan.site.projectewok.util.forum.MemberForumViewContext.java
License:Open Source License
@Override public List<Forum> getForums(Session sess, ForumCategory context, User viewer, long offset, long count) { StringBuilder q = new StringBuilder(); q.append("SELECT * FROM FORUM f "); q.append(//from w w w . j a v a2 s .com "WHERE (f.DTYPE!='GroupForum' OR f.group_id IN (SELECT group_id FROM groupmembers WHERE user_id = :viewer)) AND f.category_id = :cat "); q.append("ORDER BY position ASC "); q.append("LIMIT :count OFFSET :offset"); SQLQuery query = sess.createSQLQuery(q.toString()); query.setLong("cat", context.getId()); query.setLong("count", count); query.setLong("offset", offset); query.setLong("viewer", viewer.getId()); query.addEntity(Forum.class); return listOf(query); }
From source file:com.tysanclan.site.projectewok.util.forum.MemberForumViewContext.java
License:Open Source License
@Override public List<ForumThread> getThreads(Session sess, Forum context, User viewer, long offset, long count) { StringBuilder q = new StringBuilder(); q.append("SELECT * FROM FORUMTHREAD FT WHERE ft.forum_id = :forum AND ft.shadow = false AND "); q.append("EXISTS (SELECT * FROM FORUMPOST FP WHERE fp.shadow = false AND fp.thread_id = ft.id) "); q.append("AND NOT EXISTS "); q.append("(SELECT * FROM trial WHERE trialthread_id = ft.id AND accused_id != :user1 "); q.append(// w w w . jav a2 s . com "AND NOT EXISTS (SELECT * FROM tuser WHERE Rank IN ('CHANCELLOR', 'SENATOR', 'TRUTHSAYER') AND id=:user2)) "); q.append("ORDER BY STICKY DESC, lastPost DESC "); q.append("LIMIT :count OFFSET :offset"); SQLQuery query = sess.createSQLQuery(q.toString()); query.setLong("forum", context.getId()); query.setLong("count", count); query.setLong("offset", offset); query.setLong("user1", viewer.getId()); query.setLong("user2", viewer.getId()); query.addEntity(ForumThread.class); return listOf(query); }
From source file:com.tysanclan.site.projectewok.util.forum.MemberForumViewContext.java
License:Open Source License
@Override public List<ForumPost> getPosts(Session sess, ForumThread context, User viewer, long offset, long count) { StringBuilder q = new StringBuilder(); q.append("SELECT * FROM FORUMPOST FP WHERE fp.shadow = false AND fp.thread_id = :thread "); q.append("ORDER BY time ASC LIMIT :count OFFSET :offset"); SQLQuery query = sess.createSQLQuery(q.toString()); query.setLong("thread", context.getId()); query.setLong("count", count); query.setLong("offset", offset); query.addEntity(ForumPost.class); return listOf(query); }
From source file:com.tysanclan.site.projectewok.util.forum.PublicForumViewContext.java
License:Open Source License
@Override public List<ForumCategory> getCategories(Session sess, User viewer, long offset, long count) { StringBuilder q = new StringBuilder(); q.append("SELECT * FROM FORUMCATEGORY FC "); q.append("WHERE EXISTS ( "); q.append("SELECT * FROM FORUM f "); q.append("WHERE f.DTYPE!='GroupForum' AND f.MEMBERSONLY=false AND f.category_id = FC.id "); q.append(") ORDER BY id ASC LIMIT :count OFFSET :offset"); SQLQuery query = sess.createSQLQuery(q.toString()); query.setLong("count", count); query.setLong("offset", offset); query.addEntity(ForumCategory.class); return listOf(query); }
From source file:com.tysanclan.site.projectewok.util.forum.PublicForumViewContext.java
License:Open Source License
@Override public List<Forum> getForums(Session sess, ForumCategory context, User viewer, long offset, long count) { StringBuilder q = new StringBuilder(); q.append("SELECT * FROM FORUM f "); q.append("WHERE f.DTYPE!='GroupForum' AND f.MEMBERSONLY=false AND f.category_id = :cat "); q.append("ORDER BY position ASC "); q.append("LIMIT :count OFFSET :offset"); SQLQuery query = sess.createSQLQuery(q.toString()); query.setLong("cat", context.getId()); query.setLong("count", count); query.setLong("offset", offset); query.addEntity(Forum.class); return listOf(query); }
From source file:com.tysanclan.site.projectewok.util.forum.PublicForumViewContext.java
License:Open Source License
@Override public List<ForumThread> getThreads(Session sess, Forum context, User viewer, long offset, long count) { StringBuilder q = new StringBuilder(); q.append("SELECT * FROM FORUMTHREAD FT WHERE ft.forum_id = :forum AND ft.shadow = false AND "); q.append("NOT EXISTS (SELECT * FROM trial WHERE trialthread_id = ft.id) AND "); q.append("EXISTS (SELECT * FROM FORUMPOST FP WHERE fp.shadow = false AND fp.thread_id = ft.id) "); q.append("ORDER BY STICKY DESC, lastPost DESC "); q.append("LIMIT :count OFFSET :offset"); SQLQuery query = sess.createSQLQuery(q.toString()); query.setLong("forum", context.getId()); query.setLong("count", count); query.setLong("offset", offset); query.addEntity(ForumThread.class); return listOf(query); }