⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hibernateservice.java

📁 Extjs2增删改查
💻 JAVA
字号:
package com.tcg.core.Utils;

import org.hibernate.Criteria;
import org.hibernate.SQLQuery;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.classic.Session;

import java.io.File;
import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: Administrator
 * Date: 2008-10-6
 * Time: 13:20:09
 * To change this template use File | Settings | File Templates.
 */
public class HibernateService {
    private static SessionFactory sessionFactory;
    private static Session session;

    static {

        try {
            // Create the SessionFactory
            sessionFactory = new Configuration().configure(new File("src/hibernate.cfg.xml"))
                    .buildSessionFactory();
            session = sessionFactory.openSession();
        }catch (Throwable ex) {
            // Make sure you log the exception, as it might be swallowed
            throw new ExceptionInInitializerError(ex);
        }
    }

    public static List findBySQL(String sql) {
        SQLQuery query = session.createSQLQuery(sql);
        List list = query.setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP).list();
        return list;
    }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -