test.java

来自「Struts2+hibernate3+spring2使用范例」· Java 代码 · 共 38 行

JAVA
38
字号
package com.game.bean.hibernate;

import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;

import com.game.products.model.Products;

public class Test {

    public static void main(String[] args) {

        try {
            SessionFactory sf =
                new Configuration().configure().buildSessionFactory();
            Session session = sf.openSession();
            Transaction tx = session.beginTransaction();

            	Products pd = new Products();
            	pd.setGameId("1");
            	pd.setGameNameCn("教父");
            	pd.setGameNameEn("Godfather");
            	pd.setGameCapacity("1");
            	pd.setGameVersion("中文版");
            	pd.setGameMedia("DVD");
                session.save(pd);

            tx.commit();
            session.close();

        } catch (HibernateException e) {
            e.printStackTrace();
        }
    }
}

⌨️ 快捷键说明

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