简体   繁体   中英

Where to put persistence.xml when using a jar inside a war?

I have thw following projects:

hbo-service
hbo-web

hbo-service is jar dependency of hbo-web (war) and it handles every persistence related functionality using JPA. I included the following persistence.xml in src/main/resources/META-INF of hbo-service:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.0" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="HBOService">    
    <exclude-unlisted-classes>false</exclude-unlisted-classes>
    <properties>
        <property name="javax.persistence.jdbc.driver" value="oracle.jdbc.driver.OracleDriver"/>
        <property name="javax.persistence.jdbc.url" value="jdbc:oracle:thin:@localhost:1521/xe"/>
        <property name="javax.persistence.jdbc.user" value="hbo"/>
        <property name="javax.persistence.jdbc.password" value="hbo"/>
    </properties>
</persistence-unit>

I keep getting the following message when deploying hbo-web in glassfish:

[2016-06-30T21:08:14.353-0500] [glassfish 4.1] [SEVERE] [] [javax.enterprise.system.core] [tid: _ThreadID=47 _ThreadName=admin-listener(2)] [timeMillis: 1467338894353] [levelValue: 1000] [[
Exception while deploying the app [hbo-web-1.0-SNAPSHOT] : Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.6.1.v20150605-31e8258): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLException: 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 Code: 0]]

I noticed no matter how I change the url, it always tries to connect to localhost at 1527 (you'll notice in persistence.xml I'm trying to connect to 1521) as if any changes I make in the file are not noticed when deploying. What am I doing wrong?

This is my web.xml just in case:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
  http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" >    

</web-app>

I finally figured out the problem and it didn't have anything to do with the persistence.xml file.

[2016-06-30T21:08:14.353-0500] [glassfish 4.1] [SEVERE] [] [javax.enterprise.system.core] [tid: _ThreadID=47 _ThreadName=admin-listener(2)] [timeMillis: 1467338894353] [levelValue: 1000] [[
Exception while deploying the app [hbo-web-1.0-SNAPSHOT] : Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.6.1.v20150605-31e8258): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLException: 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 Code: 0]]

The message shows that there's a problem in 1527 port, which is the port glassfish uses for its connection pool. Turned out this service was off so all I had to do was go to Glassfish Administration Console and turn on the connection pool.

Hope it helps!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM