Maven Spring MVC + JPA Project

Asked

Viewed 177 times

1

I’m new to Spring MVC, created an example Maven project for Spring MVC using Hibernate and JPA. I found some problems when configuring persistence.xml but I could not use dartasource managed by jboss, I left it aside, now when I try to give an input 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 am 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 Setup

<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 still worked. If anyone can help me, and explain how to point to the jboss datasource later. Thank you.

  • What problem do you have when doing lookup of the DS that is in Jboss? Other things: if you lookup for EMF you don’t need to do DS; transaction type must be JTA;

  • Then the models I found on the internet of how to use DS ñ worked gave error in the spring datasource

1 answer

0

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.