Example usage for org.hibernate Session createSQLQuery

List of usage examples for org.hibernate Session createSQLQuery

Introduction

In this page you can find the example usage for org.hibernate Session createSQLQuery.

Prototype

@Override
    NativeQuery createSQLQuery(String queryString);

Source Link

Usage

From source file:com.admin.product.Posts.java

@Override
public List get() {
    Session s = HibernateUtil.currentSession();
    HibernateUtil.beginTransaction();/*from  ww  w.  j  a  v a  2  s.  com*/

    String sql = "select * from post";
    List<post> list = s.createSQLQuery(sql).addEntity(post.class).list();
    //System.out.println(hql);
    HibernateUtil.commitTransaction();//??
    HibernateUtil.closeSession();

    return list;
}

From source file:com.admin.product.Posts.java

@Override
public boolean changeStatus(String status, String id) {
    Session s = HibernateUtil.currentSession();
    HibernateUtil.beginTransaction();/*from  w w w . j av a 2 s  .c  om*/
    //String hql = "insert into user(user_name,password,mail,register_date,pic_id) " + "values('?','?','?',SYSDATE(),?)";
    //List<user> list = s.createQuery(hql).setString(0, name).setString(1, pass).setString(2, mail).setString(3, pic_id).list();

    String sql = "update post set available = ? where post_id = ?";
    int back = s.createSQLQuery(sql).setString(0, status).setString(1, id).executeUpdate();
    HibernateUtil.commitTransaction();//??
    HibernateUtil.closeSession();

    return back > 0;
}

From source file:com.admin.product.Replys.java

@Override
public List get() {
    Session s = HibernateUtil.currentSession();
    HibernateUtil.beginTransaction();/*from  w  w  w .jav  a2s .  co m*/

    String sql = "select * from reply";
    List<reply> list = s.createSQLQuery(sql).addEntity(reply.class).list();
    //System.out.println(hql);
    HibernateUtil.commitTransaction();//??
    HibernateUtil.closeSession();

    return list;
}

From source file:com.admin.product.Replys.java

@Override
public boolean changeStatus(String status, String id) {
    Session s = HibernateUtil.currentSession();
    HibernateUtil.beginTransaction();//w w w.jav  a 2  s  .c  o  m
    //String hql = "insert into user(user_name,password,mail,register_date,pic_id) " + "values('?','?','?',SYSDATE(),?)";
    //List<user> list = s.createQuery(hql).setString(0, name).setString(1, pass).setString(2, mail).setString(3, pic_id).list();

    String sql = "update reply set available = ? where reply_id = ?";
    int back = s.createSQLQuery(sql).setString(0, status).setString(1, id).executeUpdate();
    HibernateUtil.commitTransaction();//??
    HibernateUtil.closeSession();

    return back > 0;
}

From source file:com.admin.product.Users.java

@Override
public List get() {
    Session s = HibernateUtil.currentSession();
    HibernateUtil.beginTransaction();//from w  w w .ja  v  a 2 s.  co m

    String sql = "select * from user";
    List<user> list = s.createSQLQuery(sql).addEntity(user.class).list();
    //System.out.println(hql);
    HibernateUtil.commitTransaction();//??
    HibernateUtil.closeSession();

    return list;
}

From source file:com.admin.product.Users.java

@Override
public boolean changeStatus(String status, String id) {
    Session s = HibernateUtil.currentSession();
    HibernateUtil.beginTransaction();//from   w  w w  . java  2s  .com
    //String hql = "insert into user(user_name,password,mail,register_date,pic_id) " + "values('?','?','?',SYSDATE(),?)";
    //List<user> list = s.createQuery(hql).setString(0, name).setString(1, pass).setString(2, mail).setString(3, pic_id).list();

    String sql = "update user set available = ? where user_id = ?";
    int back = s.createSQLQuery(sql).setString(0, status).setString(1, id).executeUpdate();
    HibernateUtil.commitTransaction();//??
    HibernateUtil.closeSession();

    return back > 0;
}

From source file:com.adsapient.shared.dao.HibernateEntityDao.java

License:Open Source License

public void executeNativeSQL(final String query) {
    logger.info("executing query : " + query);
    getHibernateTemplate().execute(new HibernateCallback() {
        public Object doInHibernate(Session session) throws HibernateException {
            return session.createSQLQuery(query).list();
        }// w  ww. java 2s .co  m
    });
    getHibernateTemplate().flush();
}

From source file:com.adsapient.shared.dao.HibernateEntityDao.java

License:Open Source License

public Integer executeQueryInsert(final String queryName) {
    return (Integer) getHibernateTemplate().execute(new HibernateCallback() {
        public Object doInHibernate(Session session) throws HibernateException {
            session.setCacheMode(CacheMode.IGNORE);
            Transaction tx = session.beginTransaction();
            Query query = session.createSQLQuery(queryName);
            Integer res = query.executeUpdate();
            tx.commit();/*from   www  .  ja v a2  s.com*/
            return res;
        }
    });
}

From source file:com.all.client.model.LocalModelDao.java

License:Apache License

@SuppressWarnings("unchecked")
public int countLooseTracks() {
    return ((Integer) hibernateTemplate.execute(new HibernateCallback() {
        @Override/*  w w  w .j  a v  a  2  s.  co  m*/
        public Object doInHibernate(Session session) throws SQLException {
            Query q = session.createSQLQuery("SELECT COUNT (track.hashcode) looseTracks "
                    + " FROM Track track LEFT JOIN PlaylistTrack playlistTrack ON playlistTrack.trackfk = track.hashcode "
                    + " WHERE playlistTrack.id is null  ");
            return q.uniqueResult();
        }
    })).intValue();
}

From source file:com.all.client.model.LocalModelDao.java

License:Apache License

/**
 * Do not use HQL, OQL or SQL for saving, deleting or updating because the
 * DaoNotifier won't be able to catch that events, and sync will be in trouble
 * and finally having unstable libraries.
 * //w ww.ja  v  a 2  s  .c om
 * @TODO This case is needed for update only one playlisttrack and not the
 *       hole playlisttrack which belongs to a specific playlist and there is
 *       no problem because playlisttrack is not syncAble.
 */
@SuppressWarnings("unchecked")
public int executeSqlUpdate(final String sql, final Map<String, Object> values) {
    return (Integer) hibernateTemplate.execute(new HibernateCallback() {
        @Override
        public Object doInHibernate(Session session) throws SQLException {
            Query q = session.createSQLQuery(sql);
            if (values != null) {
                for (String param : values.keySet()) {
                    q.setParameter(param, values.get(param));
                }
            }
            return q.executeUpdate();
        }
    });
}