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();}}?
?请君动手搞一搞,为求得一个体会
?
?