我正在从hibernate 3.0迁移到4.1。 我有一个代码片段用于在我的应用程序中初始化hibernate。
ServiceRegistryBuilder srBuilder = new ServiceRegistryBuilder();
srBuilder.configure();
ServiceRegistry serviceRegistry = srBuilder.buildServiceRegistry();
// Initializes the session factory.
sessionConfiguration = new Configuration().configure();
sessionFactory = sessionConfiguration.buildSessionFactory(serviceRegistry);
sessionSettings = sessionConfiguration.buildSettings(serviceRegistry);
我在srBuilder.confiugre()中遇到异常。 异常堆栈跟踪: 虽然例外说“超时”,但不确定这是什么:
Caused by: org.hibernate.internal.util.config.ConfigurationException: Unable to perform unmarshalling at line number 0 and column 0 in RESOURCE hibernate.cfg.xml. Message: null
at org.hibernate.service.internal.JaxbProcessor.unmarshal(JaxbProcessor.java:120)
at org.hibernate.service.internal.JaxbProcessor.unmarshal(JaxbProcessor.java:69)
at org.hibernate.service.ServiceRegistryBuilder.configure(ServiceRegistryBuilder.java:162)
at org.hibernate.service.ServiceRegistryBuilder.configure(ServiceRegistryBuilder.java:147)
at com.vmware.vim.vcenter.das.dao.impl.HibernateUtils.init(HibernateUtils.java:76)
... 24 more
Caused by: javax.xml.bind.UnmarshalException
- with linked exception:
[com.ctc.wstx.exc.WstxIOException: Connection timed out: connect]
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.handleStreamException(Unknown Source)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(Unknown Source)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(Unknown Source)
at org.hibernate.service.internal.JaxbProcessor.unmarshal(JaxbProcessor.java:108)
... 28 more
Caused by: com.ctc.wstx.exc.WstxIOException: Connection timed out: connect
at com.ctc.wstx.sr.StreamScanner.throwFromIOE(StreamScanner.java:683)
at com.ctc.wstx.sr.BasicStreamReader.next(BasicStreamReader.java:1086)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.StAXStreamConnector.bridge(Unknown Source)
... 31 more
Caused by: java.net.ConnectException: Connection timed out: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
答案 0 :(得分:1)
如果您使用的是Hibernate.cfg.xml,
你可以这样试试:Configuration configuration = new Configuration().configure();
ServiceRegistryBuilder serviceRegistryBuilder = new ServiceRegistryBuilder();
serviceRegistryBuilder.applySettings(configuration.getProperties());
ServiceRegistry serviceRegistry = serviceRegistryBuilder.buildServiceRegistry();
sessionFactory = configuration.buildSessionFactory(serviceRegistry);