Chinaunix
标题:
hibernate4的一些问题
[打印本页]
作者:
itbigirl
时间:
2013-08-26 23:31
标题:
hibernate4的一些问题
下面是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.xml
hibernate3 好像没有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这个包还在?
欢迎光临 Chinaunix (http://bbs.chinaunix.net/)
Powered by Discuz! X3.2