Maven Spring Project MVC + JPA

1

I'm new to Spring MVC, I created an Maven sample project for Spring MVC using Hibernate and JPA. I found some problems when setting up persistence.xml but I was not able to use dartasource managed by jboss, I left that aside, now when I try to give an insert the following error occurs.

16:35:49,057 WARN  [org.jboss.jca.core.connectionmanager.pool.strategy.OnePool] (JCA PoolFiller) IJ000610: Unable to fill pool: javax.resource.ResourceException: Could not create connection
at org.jboss.jca.adapters.jdbc.local.LocalManagedConnectionFactory.getLocalManagedConnection(LocalManagedConnectionFactory.java:324)
at org.jboss.jca.adapters.jdbc.local.LocalManagedConnectionFactory.createManagedConnection(LocalManagedConnectionFactory.java:281)
at org.jboss.jca.core.connectionmanager.pool.mcp.SemaphoreArrayListManagedConnectionPool.createConnectionEventListener(SemaphoreArrayListManagedConnectionPool.java:842) [ironjacamar-core-impl-1.0.26.Final-redhat-1.jar:1.0.26.Final-redhat-1]
at org.jboss.jca.core.connectionmanager.pool.mcp.SemaphoreArrayListManagedConnectionPool.fillToMin(SemaphoreArrayListManagedConnectionPool.java:783) [ironjacamar-core-impl-1.0.26.Final-redhat-1.jar:1.0.26.Final-redhat-1]
at org.jboss.jca.core.connectionmanager.pool.mcp.PoolFiller.run(PoolFiller.java:97) [ironjacamar-core-impl-1.0.26.Final-redhat-1.jar:1.0.26.Final-redhat-1]
at java.lang.Thread.run(Thread.java:745) [rt.jar:1.7.0_79]
Caused by: java.sql.SQLRecoverableException: Erro de ES: The Network Adapter could not establish the connection
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:489)
at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:553)
at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:254)
at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:32)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:528)
at org.jboss.jca.adapters.jdbc.local.LocalManagedConnectionFactory.getLocalManagedConnection(LocalManagedConnectionFactory.java:296)
... 5 more
Caused by: oracle.net.ns.NetException: The Network Adapter could not establish the connection
at oracle.net.nt.ConnStrategy.execute(ConnStrategy.java:439)
at oracle.net.resolver.AddrResolution.resolveAndExecute(AddrResolution.java:454)
at oracle.net.ns.NSProtocol.establishConnection(NSProtocol.java:693)
at oracle.net.ns.NSProtocol.connect(NSProtocol.java:251)
at oracle.jdbc.driver.T4CConnection.connect(T4CConnection.java:1140)
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:340)
... 10 more
Caused by: java.net.ConnectException: Connection timed out: connect
at java.net.TwoStacksPlainSocketImpl.socketConnect(Native Method) [rt.jar:1.7.0_79]
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339) [rt.jar:1.7.0_79]
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200) [rt.jar:1.7.0_79]
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182) [rt.jar:1.7.0_79]
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172) [rt.jar:1.7.0_79]
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) [rt.jar:1.7.0_79]
at java.net.Socket.connect(Socket.java:579) [rt.jar:1.7.0_79]
at oracle.net.nt.TcpNTAdapter.connect(TcpNTAdapter.java:149)
at oracle.net.nt.ConnOption.connect(ConnOption.java:133)
at oracle.net.nt.ConnStrategy.execute(ConnStrategy.java:405)
... 15 more

Persistence.xml

<persistence-unit name="taskbox">        
    <jta-data-source>java:jboss/datasources/taskbox</jta-data-source>
    <properties>
        <property name="jboss.entity.manager.factory.jndi.name" value="java:jboss/taskbox/persistence-postgres" />
        <!-- Properties for Hibernate -->
        <property name="hibernate.hbm2ddl.auto" value="create-drop" />
        <property name="hibernate.show_sql" value="false" />
    </properties>
</persistence-unit>

Datasource I'm using

<datasource jndi-name="java:jboss/datasources/taskbox"
            pool-name="projetofinal" enabled="true"
            use-java-context="true">
    <connection-url>jdbc:postgresql://localhost:5432/taskbox</connection-url>
    <driver>org.postgresql</driver>
    <security>
        <user-name>postgres</user-name>
        <password>postgres</password>
    </security>
</datasource>

Bean Configuration

<jee:jndi-lookup jndi-name="java:jboss/taskbox/persistence-postgres" id="entityManagerFactory"
                 expected-type="javax.persistence.EntityManagerFactory" />

<bean id="entityManager" class="org.springframework.orm.jpa.support.SharedEntityManagerBean">
    <property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>

<jee:jndi-lookup jndi-name="java:jboss/datasources/taskbox" id="dataSource" expected-type="javax.sql.DataSource" />

<tx:jta-transaction-manager />

Factory.java

@Autowired
private EntityManager em;

protected EntityManager getEntityManager() {
    return em;
}

I tried to use @PersistContext instead of @Autowired but it worked. If someone can help me, and explain to me how to point to the jboss datasource later. Thank you.

    
asked by anonymous 13.03.2016 / 22:34

1 answer

0

I solved one of the problems! To the error I posted in the stacktrace, I was able to resolve using the @Transactional annotation of spring in the repository implementation. Now you just need to try to point to the datasource configured in jboss.

    
15.03.2016 / 01:19