hibernate3.6基础配置
来源:互联网 发布:圆通快递淘宝价格表 编辑:程序博客网 时间:2024/06/05 01:59
最近一段时间学习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的对应关系一定要正确。否则会出现这样或者那样的错误。
- hibernate3.6基础配置
- hibernate3.6基础配置
- Hibernate3.6二级缓存配置 - ehcache
- Hibernate3 jndi 配置
- Hibernate3连接池配置
- hibernate3+spring2集成配置
- Hibernate3.3.2配置笔记
- hibernate3配置详解
- Spring Hibernate3 配置 C3P0
- Struts2+Spring3+hibernate3配置
- hibernate3 注解配置大全
- hibernate3 注解配置大全
- hibernate3-maven-plugin配置
- Spring Hibernate3 配置 C3P0
- hibernate3 配置log4j
- 5hibernate3配置参数
- hibernate3.6
- hibernate3(6)
- 在arm嵌入式linux下解析XML文件(转)
- 开发者必备的网站(不断更新)
- Android核心模块及相关技术(转)
- Misbehaving Outlook Email and Microsoft
- 细谈HashMap
- hibernate3.6基础配置
- Android的源代码结构
- 系统集成项目管理工程师复习(2)
- Firefox不能接受自签名证书
- 求最小不重复数
- 5个馒头与100单生意
- ASP.NET 网站预编译
- domain-driven-design学习
- Android的应用程序结构分析:HelloActivity