免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 24685 | 回复: 0

hibernate4的一些问题 [复制链接]

论坛徽章:
0
发表于 2013-08-26 23:31 |显示全部楼层
下面是hibernate3的测试:

        private static SessionFactory sessionFactory;

private static SessionFactory configureSessionFactory() throws HibernateException {

   Configuration configuration = new Configuration().configure();

   sessionFactory =configuration.buildSessionFactory();

   return sessionFactory;

}

@Test

public void testAdd(){

Session session = TestHibernate01.configureSessionFactory().openSession();

session.beginTransaction();

User u = new User();

u.setNickname("xiaosan";

u.setUsername("小三";

u.setBorn(new Date());

session.save(u);

session.getTransaction().commit();

}

pom.xmlhibernate3 好像没有javassist)

<!-- hibernate3 -->

<dependency>

<groupId>org.hibernate</groupId>

<artifactId>hibernate-core</artifactId>

<version>3.6.10.Final</version>

</dependency>



   <dependency>

<groupId>javassist</groupId>

<artifactId>javassist</artifactId>

<version>3.12.1.GA</version>

</dependency>

            

<!-- log4j -->

<dependency>

<groupId>log4j</groupId>

<artifactId>log4j</artifactId>

<version>1.2.17</version>

</dependency>

<!-- mysql数据库驱动 -->

<dependency>

<groupId>mysql</groupId>

<artifactId>mysql-connector-java</artifactId>

<version>5.1.21</version>

</dependency>



hibernate3 是没有问题的。



下面是hibernate4的测试:

private static SessionFactory sessionFactory;

private static ServiceRegistry serviceRegistry;

private static SessionFactory configureSessionFactory() throws HibernateException {

   Configuration configuration = new Configuration().configure();

   serviceRegistry =new ServiceRegistryBuilder().applySettings(configuration.getProperties()).buildServiceRegistry();   

   sessionFactory =configuration.buildSessionFactory(serviceRegistry);

   return sessionFactory;

}

@Test

public void testAdd(){

Session session = TestHibernate01.configureSessionFactory().openSession();

session.beginTransaction();

User u = new User();

u.setNickname("xiaosan";

u.setUsername("小三";

u.setBorn(new Date());

session.save(u);

session.getTransaction().commit();

}



pom.xml (hibernate4 是自带javassist的):

<!-- hibernate4 -->

<dependency>

<groupId>org.hibernate</groupId>

<artifactId>hibernate-core</artifactId>

<version>4.1.7.Final</version>

</dependency>

<!-- hibernate3 -->

<!-- <dependency>

<groupId>org.hibernate</groupId>

<artifactId>hibernate-core</artifactId>

<version>3.6.10.Final</version>

</dependency> -->



<!--    <dependency>

<groupId>javassist</groupId>

<artifactId>javassist</artifactId>

<version>3.12.1.GA</version>

</dependency> -->

            

<!-- log4j -->

<dependency>

<groupId>log4j</groupId>

<artifactId>log4j</artifactId>

<version>1.2.17</version>

</dependency>

<!-- mysql数据库驱动 -->

<dependency>

<groupId>mysql</groupId>

<artifactId>mysql-connector-java</artifactId>

<version>5.1.21</version>

</dependency>



测试时是报错 ,错误应该是与javassist包有关,但是hibernate4.1.7.Final 自带javassist-3.15.0-GA.jar,后来加上

   <dependency>

<groupId>javassist</groupId>

<artifactId>javassist</artifactId>

<version>3.12.1.GA</version>

</dependency>

然后测试通过了。应该是包的问题,但是是hibernate4依赖提供的官方javassist-3.15.0-GA.jar,不知道为什么?可能引包的时候要注意了。



然后:<dependency>

<groupId>org.hibernate</groupId>

<artifactId>hibernate-core</artifactId>

<version>4.1.7.Final</version>

<exclusions>

<exclusion>

<groupId>javassist</groupId>

<artifactId>javassist</artifactId>

</exclusion>

</exclusions>

</dependency>



我排除javassist了,但是javassist-3.15.0-GA.jar这个包还在?
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP