hibernate3.6基础配置

最近一段时间学习hibernate3.6。发现的一些问题,但是最终还是解决了,现在把使用hibernate3.6的基本步骤在这里跟大家分享一下: 首先需要基本的jar包: cglib-2.2.jar commons-collection-3.2.jar dom4j-1.6.1.jar hibernate3.jar javassist-3.12.0.GA.jar jta-1.1.jar slf4j-api-1.6.1.jar slf4j-nop-1.6.1.jar antlr-2.7.6.jar 使用annotation时还需要下面的jar包: hibernate-jpa-2.0.api.1.0.0.Final.jar hibernate3.6已经把annotation完全融入进来,所以没有必要再去下载hibernate-annotation3.4。GA 关于hibernate.cfg.xml的配置就不多说了,重要的是里面的名称要对应。否则会出现类似于: Unable to instantiate default tuplizer [org.hibernate.tuple.entity.PojoEntityTuplizer] 这样的错误。我使用的工具类HibernateSessionFactory如下: import org.hibernate.SessionFactory; import org.hibernate.cfg.Configuration; public class HibernateSessionFactory { private static final SessionFactory sessionFactory = buildSessionFactory(); private static SessionFactory buildSessionFactory() { try { // Create the SessionFactory from hibernate.cfg.xml return new Configuration().configure().buildSessionFactory(); } catch (Throwable ex) { // Make sure you log the exception, as it might be swallowed System.err.println("出错了Initial SessionFactory creation failed." + ex); throw new ExceptionInInitializerError(ex); } } public static SessionFactory getSessionFactory() { return sessionFactory; } } 这里需要说明的是,由于hibernate3.6已经把annotation集成进来,所以我们是new Configuration(),而不是new AnnotationConfiguration()。因为后者在3.6版本里面已经不被推荐使用了,或者说已经废止了。 接下来需要如果使用我想就不用跟大家细说了,按照原来的规则去写代码就是了。其实最重要的还是hibernate.cfg.cml的配置和model层里annotation的对应关系一定要正确。否则会出现这样或者那样的错误。 本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/tjpudingmw/archive/2010/10/15/5942410.aspx

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值