2016-10-03 208 views
1

我有以下persistence文件 -無法連接到MySQL - Glassfish和Hibernate的

<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"> 

<persistence-unit name="unit" > 
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider> 

<properties> 
    <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" /> 
    <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver" /> 
    <property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/db" /> 
    <property name="hibernate.connection.username" value="user" /> 
    <property name="hibernate.connection.password" value="pwd" /> 

現在,當我在GlassFish上部署此 - 生成日誌如下 -

HHH000204: Processing PersistenceUnitInfo [ 
name: application 
...] 
HHH000412: Hibernate Core {5.2.2.Final} 
HHH000206: hibernate.properties not found 
HHH000021: Bytecode provider name : javassist 
HCANN000001: Hibernate Commons Annotations {5.0.1.Final} 
Warning: RAR5038:Unexpected exception while creating resource for pool DerbyPool. Exception : javax.resource.spi.ResourceAllocationException: Connection could not be allocated because: java.net.ConnectException : Error connecting to server localhost on port 1527 with message Connection refused: connect. 
Warning: RAR5117 : Failed to obtain/create connection from connection pool [ DerbyPool ]. Reason : com.sun.appserv.connectors.internal.api.PoolingException: Connection could not be allocated because: java.net.ConnectException : Error connecting to server localhost on port 1527 with message Connection refused: connect. 
Warning: RAR5114 : Error allocating connection : [Error in allocating a connection. Cause: Connection could not be allocated because: java.net.ConnectException : Error connecting to server localhost on port 1527 with message Connection refused: connect.] 
WARN: HHH000342: Could not obtain connection to query metadata : Error in allocating a connection. Cause: Connection could not be allocated because: java.net.ConnectException : Error connecting to server localhost on port 1527 with message Connection refused: connect. 
Info: HHH000400: Using dialect: org.hibernate.dialect.MySQLDialect 
Info: HHH000422: Disabling contextual LOB creation as connection was null 
Info: HHH000397: Using ASTQueryTranslatorFactory 
Info: Loading application [application] at [/application] 
Info: application was successfully deployed in 14,905 milliseconds. 

玻璃魚爲什麼抱怨德比?我沒有使用它。

而且,當我嘗試訪問其他服務哪位內部無二的EntityManager - 我得到下面的堆棧跟蹤 -

2016-10-03T12:41:03.337+0530|Info: HHH000204: Processing PersistenceUnitInfo [ 
name: unit 
...] 
WARN: HHH10001002: Using Hibernate built-in connection pool (not for production use!) 
Info: HHH10001005: using driver [com.mysql.jdbc.Driver] at URL [jdbc:mysql://localhost:3306/db] 
Info: HHH10001001: Connection properties: {user=user, password=****} 
Info: HHH10001003: Autocommit mode: false 
Info: HHH000115: Hibernate connection pool size: 20 (min=1) 
Info: HHH000400: Using dialect: org.hibernate.dialect.MySQLDialect 
Info: HHH000423: Disabling contextual LOB creation as JDBC driver reported JDBC version [3] less than 4 
Info: HHH000397: Using ASTQueryTranslatorFactory 
Info: not null <<<<<<---------- this is my EntityManager instance which is not null 
Warning: RAR5038:Unexpected exception while creating resource for pool DerbyPool. Exception : javax.resource.spi.ResourceAllocationException: Connection could not be allocated because: java.net.ConnectException : Error connecting to server localhost on port 1527 with message Connection refused: connect. 
Warning: RAR5117 : Failed to obtain/create connection from connection pool [ DerbyPool ]. Reason : com.sun.appserv.connectors.internal.api.PoolingException: Connection could not be allocated because: java.net.ConnectException : Error connecting to server localhost on port 1527 with message Connection refused: connect. 
Warning: RAR5114 : Error allocating connection : [Error in allocating a connection. Cause: Connection could not be allocated because: java.net.ConnectException : Error connecting to server localhost on port 1527 with message Connection refused: connect.] 
WARN: SQL Error: 0, SQLState: null 
ERROR: Error in allocating a connection. Cause: Connection could not be allocated because: java.net.ConnectException : Error connecting to server localhost on port 1527 with message Connection refused: connect. 
ERROR: HHH000337: Unable to mark for rollback on PersistenceException: 
org.hibernate.resource.transaction.backend.jta.internal.JtaPlatformInaccessibleException: Unable to access TransactionManager or UserTransaction to make physical transaction delegate 
at org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoordinatorImpl.makePhysicalTransactionDelegate(JtaTransactionCoordinatorImpl.java:229) 
at org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoordinatorImpl.getTransactionDriverControl(JtaTransactionCoordinatorImpl.java:203) 
at org.hibernate.engine.transaction.internal.TransactionImpl.<init>(TransactionImpl.java:37) 
at org.hibernate.internal.AbstractSharedSessionContract.accessTransaction(AbstractSharedSessionContract.java:372) 
at org.hibernate.internal.AbstractSharedSessionContract.markForRollbackOnly(AbstractSharedSessionContract.java:342) 
at org.hibernate.internal.ExceptionConverterImpl.handlePersistenceException(ExceptionConverterImpl.java:271) 
at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:148) 
at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:155) 
at org.hibernate.query.internal.AbstractProducedQuery.list(AbstractProducedQuery.java:1407) 
at org.hibernate.Query.getResultList(Query.java:417) 
at org.hibernate.query.criteria.internal.compile.CriteriaQueryTypeQueryAdapter.getResultList(CriteriaQueryTypeQueryAdapter.java:72) 
at com.sun.enterprise.container.common.impl.QueryWrapper.getResultList(QueryWrapper.java:84) 
at com.sun.enterprise.container.common.impl.TypedQueryWrapper.getResultList(TypedQueryWrapper.java:73) 
at RESTClass.findAll(RESTClass.java:76) 
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
at java.lang.reflect.Method.invoke(Method.java:498) 
at org.glassfish.jersey.server.model.internal.ResourceMethodInvocationHandlerFactory$1.invoke(ResourceMethodInvocationHandlerFactory.java:81) 
at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher$1.run(AbstractJavaResourceMethodDispatcher.java:144) 
at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.invoke(AbstractJavaResourceMethodDispatcher.java:161) 
at org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider$TypeOutInvoker.doDispatch(JavaResourceMethodDispatcherProvider.java:205) 
at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.dispatch(AbstractJavaResourceMethodDispatcher.java:99) 
at org.glassfish.jersey.server.model.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:389) 
at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:347) 
at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:102) 
at org.glassfish.jersey.server.ServerRuntime$2.run(ServerRuntime.java:326) 
at org.glassfish.jersey.internal.Errors$1.call(Errors.java:271) 
at org.glassfish.jersey.internal.Errors$1.call(Errors.java:267) 
at org.glassfish.jersey.internal.Errors.process(Errors.java:315) 
at org.glassfish.jersey.internal.Errors.process(Errors.java:297) 
at org.glassfish.jersey.internal.Errors.process(Errors.java:267) 
at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:317) 
at org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:305) 
at org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:1154) 
at org.glassfish.jersey.servlet.WebComponent.serviceImpl(WebComponent.java:471) 
at org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:425) 
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:383) 
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:336) 
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:223) 
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1681) 
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:318) 
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160) 
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734) 
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673) 
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99) 
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174) 
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:416) 
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:283) 
at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:466) 
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:169) 
at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:206) 
at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:180) 
at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:235) 
at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119) 
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:284) 
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:201) 
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:133) 
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:112) 
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77) 
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:526) 
at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112) 
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117) 
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56) 
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137) 
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:591) 
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:571) 
at java.lang.Thread.run(Thread.java:745) 

Warning: StandardWrapperValve[rest_servlet]: Servlet.service() for servlet rest_servlet threw exception 
java.net.ConnectException: Connection refused: connect 
at java.net.DualStackPlainSocketImpl.connect0(Native Method) 
at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:79) 
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350) 
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206) 
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188) 
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172) 
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) 
at java.net.Socket.connect(Socket.java:589) 
at java.net.Socket.connect(Socket.java:538) 
at java.net.Socket.<init>(Socket.java:434) 
at java.net.Socket.<init>(Socket.java:211) 
at javax.net.DefaultSocketFactory.createSocket(SocketFactory.java:271) 
at org.apache.derby.client.net.OpenSocketAction.run(Unknown Source) 
at org.apache.derby.client.net.OpenSocketAction.run(Unknown Source) 
at java.security.AccessController.doPrivileged(Native Method) 
at org.apache.derby.client.net.NetAgent.<init>(Unknown Source) 
at org.apache.derby.client.net.NetConnection.newAgent_(Unknown Source) 
at org.apache.derby.client.am.Connection.initConnection(Unknown Source) 
at org.apache.derby.client.am.Connection.<init>(Unknown Source) 
at org.apache.derby.client.net.NetConnection.<init>(Unknown Source) 
at org.apache.derby.client.net.NetConnection40.<init>(Unknown Source) 
at org.apache.derby.client.net.ClientJDBCObjectFactoryImpl40.newNetConnection(Unknown Source) 
at org.apache.derby.jdbc.ClientBaseDataSourceRoot.getConnectionX(Unknown Source) 
at org.apache.derby.jdbc.ClientBaseDataSourceRoot.getConnection(Unknown Source) 
at com.sun.gjc.spi.DSManagedConnectionFactory.createManagedConnection(DSManagedConnectionFactory.java:117) 
at com.sun.enterprise.resource.allocator.LocalTxConnectorAllocator.createResource(LocalTxConnectorAllocator.java:87) 
at com.sun.enterprise.resource.pool.ConnectionPool.createSingleResource(ConnectionPool.java:907) 
at com.sun.enterprise.resource.pool.ConnectionPool.createResource(ConnectionPool.java:1189) 
at com.sun.enterprise.resource.pool.datastructure.RWLockDataStructure.addResource(RWLockDataStructure.java:98) 
at com.sun.enterprise.resource.pool.ConnectionPool.addResource(ConnectionPool.java:282) 
at com.sun.enterprise.resource.pool.ConnectionPool.createResourceAndAddToPool(ConnectionPool.java:1512) 
at com.sun.enterprise.resource.pool.ConnectionPool.createResources(ConnectionPool.java:944) 
at com.sun.enterprise.resource.pool.ConnectionPool.initPool(ConnectionPool.java:230) 
at com.sun.enterprise.resource.pool.ConnectionPool.internalGetResource(ConnectionPool.java:511) 
at com.sun.enterprise.resource.pool.ConnectionPool.getResource(ConnectionPool.java:381) 
at com.sun.enterprise.resource.pool.PoolManagerImpl.getResourceFromPool(PoolManagerImpl.java:245) 
at com.sun.enterprise.resource.pool.PoolManagerImpl.getResource(PoolManagerImpl.java:171) 
at com.sun.enterprise.connectors.ConnectionManagerImpl.getResource(ConnectionManagerImpl.java:360) 
at com.sun.enterprise.connectors.ConnectionManagerImpl.internalGetConnection(ConnectionManagerImpl.java:307) 
at com.sun.enterprise.connectors.ConnectionManagerImpl.allocateConnection(ConnectionManagerImpl.java:196) 
at com.sun.enterprise.connectors.ConnectionManagerImpl.allocateConnection(ConnectionManagerImpl.java:171) 
at com.sun.enterprise.connectors.ConnectionManagerImpl.allocateConnection(ConnectionManagerImpl.java:166) 
at com.sun.gjc.spi.base.AbstractDataSource.getConnection(AbstractDataSource.java:147) 
at org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl.getConnection(DatasourceConnectionProviderImpl.java:122) 
at org.hibernate.internal.NonContextualJdbcConnectionAccess.obtainConnection(NonContextualJdbcConnectionAccess.java:35) 
at org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl.acquireConnectionIfNeeded(LogicalConnectionManagedImpl.java:99) 
at org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl.getPhysicalConnection(LogicalConnectionManagedImpl.java:129) 
at org.hibernate.engine.jdbc.internal.StatementPreparerImpl.connection(StatementPreparerImpl.java:47) 
at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$5.doPrepare(StatementPreparerImpl.java:146) 
at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$StatementPreparationTemplate.prepareStatement(StatementPreparerImpl.java:172) 
at org.hibernate.engine.jdbc.internal.StatementPreparerImpl.prepareQueryStatement(StatementPreparerImpl.java:148) 
at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1940) 
at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1909) 
at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1887) 
at org.hibernate.loader.Loader.doQuery(Loader.java:932) 
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:349) 
at org.hibernate.loader.Loader.doList(Loader.java:2615) 
at org.hibernate.loader.Loader.doList(Loader.java:2598) 
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2430) 
at org.hibernate.loader.Loader.list(Loader.java:2425) 
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:502) 
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:371) 
at org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:216) 
at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1458) 
at org.hibernate.query.internal.AbstractProducedQuery.doList(AbstractProducedQuery.java:1426) 
at org.hibernate.query.internal.AbstractProducedQuery.list(AbstractProducedQuery.java:1398) 
at org.hibernate.Query.getResultList(Query.java:417) 
at org.hibernate.query.criteria.internal.compile.CriteriaQueryTypeQueryAdapter.getResultList(CriteriaQueryTypeQueryAdapter.java:72) 
at com.sun.enterprise.container.common.impl.QueryWrapper.getResultList(QueryWrapper.java:84) 
at com.sun.enterprise.container.common.impl.TypedQueryWrapper.getResultList(TypedQueryWrapper.java:73) 
at com.accountpro.entity.service.AbstractFacade.findAll(AbstractFacade.java:43) 
at com.accountpro.entity.service.CityFacadeREST.findAll(CityFacadeREST.java:76) 
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
at java.lang.reflect.Method.invoke(Method.java:498) 
at org.glassfish.jersey.server.model.internal.ResourceMethodInvocationHandlerFactory$1.invoke(ResourceMethodInvocationHandlerFactory.java:81) 
at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher$1.run(AbstractJavaResourceMethodDispatcher.java:144) 
at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.invoke(AbstractJavaResourceMethodDispatcher.java:161) 
at org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider$TypeOutInvoker.doDispatch(JavaResourceMethodDispatcherProvider.java:205) 
at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.dispatch(AbstractJavaResourceMethodDispatcher.java:99) 
at org.glassfish.jersey.server.model.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:389) 
at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:347) 
at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:102) 
at org.glassfish.jersey.server.ServerRuntime$2.run(ServerRuntime.java:326) 
at org.glassfish.jersey.internal.Errors$1.call(Errors.java:271) 
at org.glassfish.jersey.internal.Errors$1.call(Errors.java:267) 
at org.glassfish.jersey.internal.Errors.process(Errors.java:315) 
at org.glassfish.jersey.internal.Errors.process(Errors.java:297) 
at org.glassfish.jersey.internal.Errors.process(Errors.java:267) 
at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:317) 
at org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:305) 
at org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:1154) 
at org.glassfish.jersey.servlet.WebComponent.serviceImpl(WebComponent.java:471) 
at org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:425) 
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:383) 
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:336) 
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:223) 
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1681) 
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:318) 
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160) 
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734) 
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673) 
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99) 
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174) 
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:416) 
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:283) 
at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:466) 
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:169) 
at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:206) 
at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:180) 
at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:235) 
at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119) 
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:284) 
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:201) 
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:133) 
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:112) 
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77) 
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:526) 
at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112) 
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117) 
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56) 
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137) 
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:591) 
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:571) 
at java.lang.Thread.run(Thread.java:745) 

有人能猜的話......喜歡什麼地方出錯了?我正嘗試使用內置的連接池來配合休眠。

更新 - 下面是我如何注入的EntityManager在我的服務類

@PersistenceContext(unitName = "unit") 
private EntityManager em; 
+0

FWIW某些Hibernate特定的配置文件不是JPA的一部分。你只需要persistence.xml –

+0

@NeilStockton謝謝。學習JPA和hibernate。將擺脫cfg文件。 – Tirath

+0

請向我們展示取回實體經理或會話的代碼。 –

回答

0

之一,如果你想使用JTA類型資源,那麼你必須在你的應用服務器宣告你的數據庫。在這種情況下,您的交易由您的應用服務器管理,您可以通過PersitenceContext注入entityManager

如果您想要在您的應用服務器中僅在您的persistence.xml(如您所做的那樣)中聲明數據庫,那麼您必須使用persistence-unit-type=RESOURCE_LOCAL。要在這種情況下檢索entityManager,您必須使用PersistenceUnit並通過EntityManagerFactory

2

在堆棧跟蹤

ERROR: Error in allocating a connection. Cause: Connection could not be allocated because: java.net.ConnectException : Error connecting to server localhost on port 1527 with message Connection refused: connect.

你可以想這個問題可能是什麼望着下面一行。第一個問題是我認爲的數據庫驅動程序問題。 1527是Glassfish應用服務器附帶的derby數據庫的默認端口號。

由於您沒有在您的配置中提供任何數據源,服務器正試圖在這種情況下找到默認的數據庫derby;但您無法連接到該數據庫,因爲您尚未提供此數據庫的任何連接信息。

所以,你必須做以下的META-INF/persistence.xml

  • 提供的transaction-type(在你的配置也被認爲是JTA,因爲你在部署上按規格JEE環境中的應用)作爲

    <persistence-unit name="unit" transaction-type="JTA"> 
    
  • 提供的jta-data-source元素的persistence-unit

    孩子

爲了使上述配置正常工作,您必須配置您的應用服務器(Glassfish)。要做到這一點,你必須下載MySQL jdbc驅動程序,解壓縮並將jar文件複製到<glassfish_installation_directory>/glassfish/domains/domain1/lib(我在這裏假設Glassfish 3.1)。原因是Glassfish沒有附帶MySQL驅動程序,所以你必須自己做。

啓動Glassfish並打開管理控制檯(http://localhost:4848)。在左窗格中打開

  1. Resources/JDBC/JDBC Connection Pools並創建一個新的連接池
  2. Resources/JDBC/JDBC Resources並創建一個新的數據源。如上所述,您向數據源提供的名稱是您在persistence.xml中必須提供的名稱。