Salve a tutti.
Mi è stato passato un progetto server java basato su spring e hibernate; dato che non ho mai avuto modo di lavorare con questi frameworks ho provato a farmi un progettino ex-novo per impratichirmi con l'ABC diquesti due strumenti.
Sto avendo, però, qualche problema con hibernate.
Nel progetto ho un file persistence.xml presente nel path mytestprj/config/hibernate in src/main/resources così definito:
codice:
<?xml version="1.0" encoding="UTF-8"?>
<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="test">
<mapping-file>/mytestprj/config/hibernate/orm.xml</mapping-file>
<exclude-unlisted-classes />
<properties>
<property name="hibernate.connection.datasource"
value="java:comp/env/jdbc/test" />
<property name="hibernate.dialect"
value="org.hibernate.dialect.MySQL5Dialect" />
<!-- Disattivo la rilevazione automatica di classi annotate e file
di mappatura -->
<property name="hibernate.archive.autodetection" value="no" />
<property name="hibernate.ejb.cfgfile"
value="/mytestprj/config/hibernate/hibernate.cfg.xml" />
<!-- Quote di tutti gli identificatori -->
<property name="hibernate.globally_quoted_identifiers"
value="true" />
<property name="hibernate.hbm2ddl.auto" value="update" />
</properties>
</persistence-unit>
</persistence>
orm.xml e hibernate.cfg.xml sono presenti nella stessa cartella di persistence.xml.
Nel file project-servlet.xml in src/main/webapp/WEB-INF ho inserito questo:
codice:
<beans:bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor">
<beans:property name="defaultPersistenceUnitName"
value="test" />
</beans:bean>
<beans:bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<beans:property name="persistenceXmlLocation" value="classpath:/mytestprj/config/hibernate/persistence.xml" />
<beans:property name="jpaVendorAdapter">
<!-- Implementazione JPA di Hibernate -->
<beans:bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" />
</beans:property>
</beans:bean>
e su tomcat il datasource è definito nel seguente modo:
codice:
<Resource
name="jdbc/test" type="javax.sql.DataSource"
maxActive="100" maxIdle="30" maxWait="10000"
url="jdbc:mysql://localhost:3306/test"
driverClassName="com.mysql.jdbc.Driver"
username="user" password="pssw"
/>
Eseguendo il server ottengo il seguente errore:
codice:
javax.servlet.ServletException: Servlet.init() for servlet project threw exception
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:314)
java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
java.lang.Thread.run(Unknown Source)
root cause
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in ServletContext resource [/WEB-INF/project-servlet.xml]: Invocation of init method failed; nested exception is org.hibernate.metamodel.source.MappingException: Error accessing stax stream
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1568)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(
root cause
com.ctc.wstx.exc.WstxIOException: Connection timed out: connect
com.ctc.wstx.sr.StreamScanner.throwFromIOE(StreamScanner.java:708)
com.ctc.wstx.sr.BasicStreamReader.next(BasicStreamReader.java:1086)
com.ctc.wstx.evt.WstxEventReader.peek(WstxEventReader.java:306)
Qualcuno ha qualche idea in merito?
Ciao, grazie