首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

Hibernate运用——自定义数据类型

2013-07-01 
Hibernate使用——自定义数据类型?1.SQL?3.hibernate.cfg.xml?4.HibernateLocalUtil.java?7.EmailList.java(

Hibernate使用——自定义数据类型

?

1.SQL

?

3.hibernate.cfg.xml

?

4.HibernateLocalUtil.java

?

7.EmailList.java(本例关键核心所在)

package learnHibernate;import java.util.ArrayList;import java.util.List;import org.hibernate.Criteria;import org.hibernate.Session;import org.hibernate.SessionFactory;import org.hibernate.Transaction;import org.junit.Test;import learnHibernate.bean.TMember;import learnHibernate.util.HibernateLocalUtil;public class TestCase2 {//@Testpublic void saveTMember() {TMember t = new TMember();List emailList = new ArrayList();emailList.add("gwoham@163.com");emailList.add("gwoham@gmail.com");emailList.add("2210635870@qq.com");t.setName("Oham");//t.setEmail(emailList);SessionFactory sessionFactory = HibernateLocalUtil.getSessionFactory();Session session = sessionFactory.openSession();Transaction tx = session.beginTransaction();session.save(t);tx.commit();session.close();}@Testpublic void selectAllTMember() {SessionFactory sessionFactory = HibernateLocalUtil.getSessionFactory();Session session = sessionFactory.openSession();Criteria criteria = session.createCriteria(TMember.class);List members = criteria.list();for(Object t : members) {TMember m = (TMember)t;List emailList = m.getEmail();if(emailList != null) {System.out.println(emailList.toString());}else {System.out.println("no email");}}session.close();}}

?

?请君动手搞一搞,为求得一个体会

?

?

热点排行