Hibernate创建SessionFactory是程序卡住不运行?

灰度乌鸦 发布于 2014/05/13 11:18
阅读 939
收藏 0

使用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 <clinit>
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 <clinit>
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都正常.

请大家指教!谢谢


加载中
返回顶部
顶部