2 dsf0075 dsf0075 于 2014.05.13 11:37 提问

Hibernate4创建SessionFactory时卡住不运行?

Hibernate4创建SessionFactory时卡住不运行?

使用Hibernate4写一个CRUD示例,javase程序,在main方法中创建sessionFactory,使用如下代码:

private HibernateUtils() {
try {
    if (this.sessionFactory == null) {
        Configuration cfg = new Configuration();
        cfg.configure(new File("hibernate.cfg.xml"));
        cfg.setNamingStrategy(ImprovedNamingStrategy.INSTANCE);
        ServiceRegistry sr =new ServiceRegistryBuilder().applySettings(cfg.getProperties()).buildServiceRegistry();
        this.sessionFactory = cfg.addAnnotatedClass(ApplyInfo.class)
                                .addAnnotatedClass(Contract.class)
                                .addAnnotatedClass(Overview.class)
                                .addAnnotatedClass(SegmentHtml.class)
                                .buildSessionFactory(sr);
        }
    } catch (Exception e) {
        e.printStackTrace();
        throw e;
    }
}

在Eclipse中普通运行就会卡住不允许,如果是debug方式运行,就没有任何问题.
卡在如下日志处

五月 13, 2014 10:34:16 上午 org.hibernate.annotations.common.Version
INFO: HCANN000001: Hibernate Commons Annotations {4.0.2.Final}
五月 13, 2014 10:34:16 上午 org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {4.2.12.Final}
五月 13, 2014 10:34:16 上午 org.hibernate.cfg.Environment
INFO: HHH000206: hibernate.properties not found
五月 13, 2014 10:34:16 上午 org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
五月 13, 2014 10:34:16 上午 org.hibernate.cfg.Configuration configure
INFO: HHH000042: Configuring from file: hibernate.cfg.xml
五月 13, 2014 10:34:17 上午 org.hibernate.cfg.Configuration doConfigure
INFO: HHH000041: Configured SessionFactory: null
五月 13, 2014 10:34:17 上午 org.hibernate.service.jdbc.connections.internal.ConnectionProviderInitiator getConfiguredConnectionProviderName
WARN: HHH000208: org.hibernate.connection.C3P0ConnectionProvider has been deprecated in favor of org.hibernate.service.jdbc.connections.internal.C3P0ConnectionProvider; that provider will be used instead.
五月 13, 2014 10:34:17 上午 org.hibernate.service.jdbc.connections.internal.ConnectionProviderInitiator instantiateExplicitConnectionProvider
INFO: HHH000130: Instantiating explicit connection provider: org.hibernate.service.jdbc.connections.internal.C3P0ConnectionProvider
五月 13, 2014 10:34:17 上午 org.hibernate.service.jdbc.connections.internal.C3P0ConnectionProvider configure
INFO: HHH010002: C3P0 using driver: com.mysql.jdbc.Driver at URL: jdbc:mysql://localhost:3306/pgdata
五月 13, 2014 10:34:17 上午 org.hibernate.service.jdbc.connections.internal.C3P0ConnectionProvider configure
INFO: HHH000046: Connection properties: {user=root, password=****}
五月 13, 2014 10:34:17 上午 org.hibernate.service.jdbc.connections.internal.C3P0ConnectionProvider configure

这句
org.hibernate.service.jdbc.connections.internal.C3P0ConnectionProvider configure​

到这里就不在向下执行.在Debug模式就没有任何问题,创建SessionFactory和Crud都正常.

数据库驱动,hibernate4小版本号够尝试换成别的版本,都没能解决问题.

请大家指教!谢谢

1个回答

u011877388
u011877388   2015.11.04 11:12

大哥,你的问题解决了嘛?我也遇到了这样的问题,求指教啊

Csdn user default icon
上传中...
上传图片
插入图片