Spring

6 respostas
M

Pessoal,

estou desenvolvendo uma aplicação e estou usando spring. Configurei tudo só que o que está ocorrendo é que quando ele chega nessa linha de código:

chamadoAbertoDao = (ChamadoAbertoDao) applicationContext.getBean("chamadoAbertoDao");

ele não passa, fica preso em uma thread, já me bati aqui e não consegui resolver.
o bean está no application context da seguinte forma:

<bean id="chamadoAbertoDao" name="chamadoAbertoDao"
          class="br.com.bacone.sicc.persistencia.dao.impl.ChamadoAbertoDaoImpl" />

Alguém pode me ajudar?

6 Respostas

lordtiago

vc tem a tela de erro que dá?

M

oi lordtiago,

Não ocorre erro algum, a aplicação cai em uma thread e fica presa, tendo eu que finalizá-la manualmente.

M

Consegui resolver. foi a falta de uma biblioteca, a sfl4j.
Estou com outro erro agora, quando eu coloca para persistir, estou fazendo assim:

this.entityManager.persist(object);

só que ele não persiste, não insere nada no banco.
ele passa pela etapa de persist do spring, só que o stacktrace ele me apresenta:

2357 [main] DEBUG org.hibernate.jdbc.AbstractBatcher  - about to open ResultSet (open ResultSets: 0, globally: 0)
2357 [main] DEBUG org.hibernate.jdbc.AbstractBatcher  - about to open ResultSet (open ResultSets: 0, globally: 0)
2357 [main] DEBUG org.hibernate.jdbc.AbstractBatcher  - about to open ResultSet (open ResultSets: 0, globally: 0)
2357 [main] DEBUG org.hibernate.jdbc.AbstractBatcher  - about to open ResultSet (open ResultSets: 0, globally: 0)
2358 [main] DEBUG org.hibernate.loader.Loader  - processing result set
2358 [main] DEBUG org.hibernate.loader.Loader  - processing result set
2358 [main] DEBUG org.hibernate.loader.Loader  - processing result set
2358 [main] DEBUG org.hibernate.loader.Loader  - processing result set
2358 [main] DEBUG org.hibernate.loader.Loader  - done processing result set (0 rows)
2358 [main] DEBUG org.hibernate.loader.Loader  - done processing result set (0 rows)
2358 [main] DEBUG org.hibernate.loader.Loader  - done processing result set (0 rows)
2358 [main] DEBUG org.hibernate.loader.Loader  - done processing result set (0 rows)
2358 [main] DEBUG org.hibernate.jdbc.AbstractBatcher  - about to close ResultSet (open ResultSets: 1, globally: 1)
2358 [main] DEBUG org.hibernate.jdbc.AbstractBatcher  - about to close ResultSet (open ResultSets: 1, globally: 1)
2358 [main] DEBUG org.hibernate.jdbc.AbstractBatcher  - about to close ResultSet (open ResultSets: 1, globally: 1)
2358 [main] DEBUG org.hibernate.jdbc.AbstractBatcher  - about to close ResultSet (open ResultSets: 1, globally: 1)
2358 [main] DEBUG org.hibernate.jdbc.AbstractBatcher  - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
2358 [main] DEBUG org.hibernate.jdbc.AbstractBatcher  - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
2358 [main] DEBUG org.hibernate.jdbc.AbstractBatcher  - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
2358 [main] DEBUG org.hibernate.jdbc.AbstractBatcher  - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
2358 [main] DEBUG org.hibernate.jdbc.AbstractBatcher  - closing statement
2358 [main] DEBUG org.hibernate.jdbc.AbstractBatcher  - closing statement
2358 [main] DEBUG org.hibernate.jdbc.AbstractBatcher  - closing statement
2358 [main] DEBUG org.hibernate.jdbc.AbstractBatcher  - closing statement
2360 [main] DEBUG org.hibernate.loader.Loader  - total objects hydrated: 0
2360 [main] DEBUG org.hibernate.loader.Loader  - total objects hydrated: 0
2360 [main] DEBUG org.hibernate.loader.Loader  - total objects hydrated: 0
2360 [main] DEBUG org.hibernate.loader.Loader  - total objects hydrated: 0
2360 [main] DEBUG org.hibernate.engine.StatefulPersistenceContext  - initializing non-lazy collections
2360 [main] DEBUG org.hibernate.engine.StatefulPersistenceContext  - initializing non-lazy collections
2360 [main] DEBUG org.hibernate.engine.StatefulPersistenceContext  - initializing non-lazy collections
2360 [main] DEBUG org.hibernate.engine.StatefulPersistenceContext  - initializing non-lazy collections
2361 [main] ERROR java.lang.Object  - Usuario não encontrado
2361 [main] ERROR java.lang.Object  - Usuario não encontrado
2361 [main] ERROR java.lang.Object  - Usuario não encontrado
2361 [main] ERROR java.lang.Object  - Usuario não encontrado
2361 [main] DEBUG org.springframework.transaction.interceptor.TransactionInterceptor  - Completing transaction for [br.com.bacone.sicc.persistencia.dao.UsuarioDao.consultarPorUsername]
2361 [main] DEBUG org.springframework.transaction.interceptor.TransactionInterceptor  - Completing transaction for [br.com.bacone.sicc.persistencia.dao.UsuarioDao.consultarPorUsername]
2361 [main] DEBUG org.springframework.transaction.interceptor.TransactionInterceptor  - Completing transaction for [br.com.bacone.sicc.persistencia.dao.UsuarioDao.consultarPorUsername]
2361 [main] DEBUG org.springframework.transaction.interceptor.TransactionInterceptor  - Completing transaction for [br.com.bacone.sicc.persistencia.dao.UsuarioDao.consultarPorUsername]
2362 [main] DEBUG org.springframework.orm.jpa.JpaTransactionManager  - Triggering beforeCommit synchronization
2362 [main] DEBUG org.springframework.orm.jpa.JpaTransactionManager  - Triggering beforeCommit synchronization
2362 [main] DEBUG org.springframework.orm.jpa.JpaTransactionManager  - Triggering beforeCommit synchronization
2362 [main] DEBUG org.springframework.orm.jpa.JpaTransactionManager  - Triggering beforeCommit synchronization
2363 [main] DEBUG org.springframework.orm.jpa.JpaTransactionManager  - Triggering beforeCompletion synchronization
2363 [main] DEBUG org.springframework.orm.jpa.JpaTransactionManager  - Triggering beforeCompletion synchronization
2363 [main] DEBUG org.springframework.orm.jpa.JpaTransactionManager  - Triggering beforeCompletion synchronization
2363 [main] DEBUG org.springframework.orm.jpa.JpaTransactionManager  - Triggering beforeCompletion synchronization
2363 [main] DEBUG org.springframework.orm.jpa.JpaTransactionManager  - Initiating transaction commit
2363 [main] DEBUG org.springframework.orm.jpa.JpaTransactionManager  - Initiating transaction commit
2363 [main] DEBUG org.springframework.orm.jpa.JpaTransactionManager  - Initiating transaction commit
2363 [main] DEBUG org.springframework.orm.jpa.JpaTransactionManager  - Initiating transaction commit
2363 [main] DEBUG org.springframework.orm.jpa.JpaTransactionManager  - Committing JPA transaction on EntityManager [org.hibernate.ejb.EntityManagerImpl@930120]
2363 [main] DEBUG org.springframework.orm.jpa.JpaTransactionManager  - Committing JPA transaction on EntityManager [org.hibernate.ejb.EntityManagerImpl@930120]
2363 [main] DEBUG org.springframework.orm.jpa.JpaTransactionManager  - Committing JPA transaction on EntityManager [org.hibernate.ejb.EntityManagerImpl@930120]
2363 [main] DEBUG org.springframework.orm.jpa.JpaTransactionManager  - Committing JPA transaction on EntityManager [org.hibernate.ejb.EntityManagerImpl@930120]
2364 [main] DEBUG org.hibernate.transaction.JDBCTransaction  - commit
2364 [main] DEBUG org.hibernate.transaction.JDBCTransaction  - commit
2364 [main] DEBUG org.hibernate.transaction.JDBCTransaction  - commit
2364 [main] DEBUG org.hibernate.transaction.JDBCTransaction  - commit
2364 [main] DEBUG org.hibernate.impl.SessionImpl  - automatically flushing session
2364 [main] DEBUG org.hibernate.impl.SessionImpl  - automatically flushing session
2364 [main] DEBUG org.hibernate.impl.SessionImpl  - automatically flushing session
2364 [main] DEBUG org.hibernate.impl.SessionImpl  - automatically flushing session
2364 [main] DEBUG org.hibernate.jdbc.JDBCContext  - before transaction completion
2364 [main] DEBUG org.hibernate.jdbc.JDBCContext  - before transaction completion
2364 [main] DEBUG org.hibernate.jdbc.JDBCContext  - before transaction completion
2364 [main] DEBUG org.hibernate.jdbc.JDBCContext  - before transaction completion
2365 [main] DEBUG org.hibernate.impl.SessionImpl  - before transaction completion
2365 [main] DEBUG org.hibernate.impl.SessionImpl  - before transaction completion
2365 [main] DEBUG org.hibernate.impl.SessionImpl  - before transaction completion
2365 [main] DEBUG org.hibernate.impl.SessionImpl  - before transaction completion
2366 [main] DEBUG org.hibernate.transaction.JDBCTransaction  - re-enabling autocommit
2366 [main] DEBUG org.hibernate.transaction.JDBCTransaction  - re-enabling autocommit
2366 [main] DEBUG org.hibernate.transaction.JDBCTransaction  - re-enabling autocommit
2366 [main] DEBUG org.hibernate.transaction.JDBCTransaction  - re-enabling autocommit
2366 [main] DEBUG org.hibernate.transaction.JDBCTransaction  - committed JDBC Connection
2366 [main] DEBUG org.hibernate.transaction.JDBCTransaction  - committed JDBC Connection
2366 [main] DEBUG org.hibernate.transaction.JDBCTransaction  - committed JDBC Connection
2366 [main] DEBUG org.hibernate.transaction.JDBCTransaction  - committed JDBC Connection
2366 [main] DEBUG org.hibernate.jdbc.JDBCContext  - after transaction completion
2366 [main] DEBUG org.hibernate.jdbc.JDBCContext  - after transaction completion
2366 [main] DEBUG org.hibernate.jdbc.JDBCContext  - after transaction completion
2366 [main] DEBUG org.hibernate.jdbc.JDBCContext  - after transaction completion
2366 [main] DEBUG org.hibernate.jdbc.ConnectionManager  - aggressively releasing JDBC connection
2366 [main] DEBUG org.hibernate.jdbc.ConnectionManager  - aggressively releasing JDBC connection
2366 [main] DEBUG org.hibernate.jdbc.ConnectionManager  - aggressively releasing JDBC connection
2366 [main] DEBUG org.hibernate.jdbc.ConnectionManager  - aggressively releasing JDBC connection
2366 [main] DEBUG org.hibernate.jdbc.ConnectionManager  - releasing JDBC connection [ (open PreparedStatements: 0, globally: 0) (open ResultSets: 0, globally: 0)]
2366 [main] DEBUG org.hibernate.jdbc.ConnectionManager  - releasing JDBC connection [ (open PreparedStatements: 0, globally: 0) (open ResultSets: 0, globally: 0)]
2366 [main] DEBUG org.hibernate.jdbc.ConnectionManager  - releasing JDBC connection [ (open PreparedStatements: 0, globally: 0) (open ResultSets: 0, globally: 0)]
2366 [main] DEBUG org.hibernate.jdbc.ConnectionManager  - releasing JDBC connection [ (open PreparedStatements: 0, globally: 0) (open ResultSets: 0, globally: 0)]
2367 [main] DEBUG org.hibernate.impl.SessionImpl  - after transaction completion
2367 [main] DEBUG org.hibernate.impl.SessionImpl  - after transaction completion
2367 [main] DEBUG org.hibernate.impl.SessionImpl  - after transaction completion
2367 [main] DEBUG org.hibernate.impl.SessionImpl  - after transaction completion
2369 [main] DEBUG org.springframework.orm.jpa.JpaTransactionManager  - Triggering afterCommit synchronization
2369 [main] DEBUG org.springframework.orm.jpa.JpaTransactionManager  - Triggering afterCommit synchronization
2369 [main] DEBUG org.springframework.orm.jpa.JpaTransactionManager  - Triggering afterCommit synchronization
2369 [main] DEBUG org.springframework.orm.jpa.JpaTransactionManager  - Triggering afterCommit synchronization
2370 [main] DEBUG org.springframework.orm.jpa.JpaTransactionManager  - Triggering afterCompletion synchronization
2370 [main] DEBUG org.springframework.orm.jpa.JpaTransactionManager  - Triggering afterCompletion synchronization
2370 [main] DEBUG org.springframework.orm.jpa.JpaTransactionManager  - Triggering afterCompletion synchronization
2370 [main] DEBUG org.springframework.orm.jpa.JpaTransactionManager  - Triggering afterCompletion synchronization
2370 [main] DEBUG org.springframework.transaction.support.TransactionSynchronizationManager  - Clearing transaction synchronization
2370 [main] DEBUG org.springframework.transaction.support.TransactionSynchronizationManager  - Clearing transaction synchronization
2370 [main] DEBUG org.springframework.transaction.support.TransactionSynchronizationManager  - Clearing transaction synchronization
2370 [main] DEBUG org.springframework.transaction.support.TransactionSynchronizationManager  - Clearing transaction synchronization
2370 [main] DEBUG org.springframework.transaction.support.TransactionSynchronizationManager  - Removed value [org.springframework.orm.jpa.EntityManagerHolder@8be1c9] for key [org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean@1947647] from thread [main]
2370 [main] DEBUG org.springframework.transaction.support.TransactionSynchronizationManager  - Removed value [org.springframework.orm.jpa.EntityManagerHolder@8be1c9] for key [org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean@1947647] from thread [main]
2370 [main] DEBUG org.springframework.transaction.support.TransactionSynchronizationManager  - Removed value [org.springframework.orm.jpa.EntityManagerHolder@8be1c9] for key [org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean@1947647] from thread [main]
2370 [main] DEBUG org.springframework.transaction.support.TransactionSynchronizationManager  - Removed value [org.springframework.orm.jpa.EntityManagerHolder@8be1c9] for key [org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean@1947647] from thread [main]
2371 [main] DEBUG org.springframework.transaction.support.TransactionSynchronizationManager  - Removed value [org.springframework.jdbc.datasource.ConnectionHolder@13d5f21] for key [org.springframework.jdbc.datasource.DriverManagerDataSource@5585dc] from thread [main]
2371 [main] DEBUG org.springframework.transaction.support.TransactionSynchronizationManager  - Removed value [org.springframework.jdbc.datasource.ConnectionHolder@13d5f21] for key [org.springframework.jdbc.datasource.DriverManagerDataSource@5585dc] from thread [main]
2371 [main] DEBUG org.springframework.transaction.support.TransactionSynchronizationManager  - Removed value [org.springframework.jdbc.datasource.ConnectionHolder@13d5f21] for key [org.springframework.jdbc.datasource.DriverManagerDataSource@5585dc] from thread [main]
2371 [main] DEBUG org.springframework.transaction.support.TransactionSynchronizationManager  - Removed value [org.springframework.jdbc.datasource.ConnectionHolder@13d5f21] for key [org.springframework.jdbc.datasource.DriverManagerDataSource@5585dc] from thread [main]
2371 [main] DEBUG org.springframework.orm.jpa.JpaTransactionManager  - Closing JPA EntityManager [org.hibernate.ejb.EntityManagerImpl@930120] after transaction
2371 [main] DEBUG org.springframework.orm.jpa.JpaTransactionManager  - Closing JPA EntityManager [org.hibernate.ejb.EntityManagerImpl@930120] after transaction
2371 [main] DEBUG org.springframework.orm.jpa.JpaTransactionManager  - Closing JPA EntityManager [org.hibernate.ejb.EntityManagerImpl@930120] after transaction
2371 [main] DEBUG org.springframework.orm.jpa.JpaTransactionManager  - Closing JPA EntityManager [org.hibernate.ejb.EntityManagerImpl@930120] after transaction
2371 [main] DEBUG org.springframework.orm.jpa.EntityManagerFactoryUtils  - Closing JPA EntityManager
2371 [main] DEBUG org.springframework.orm.jpa.EntityManagerFactoryUtils  - Closing JPA EntityManager
2371 [main] DEBUG org.springframework.orm.jpa.EntityManagerFactoryUtils  - Closing JPA EntityManager
2371 [main] DEBUG org.springframework.orm.jpa.EntityManagerFactoryUtils  - Closing JPA EntityManager
2372 [main] DEBUG org.hibernate.impl.SessionImpl  - closing session
2372 [main] DEBUG org.hibernate.impl.SessionImpl  - closing session
2372 [main] DEBUG org.hibernate.impl.SessionImpl  - closing session
2372 [main] DEBUG org.hibernate.impl.SessionImpl  - closing session
2372 [main] DEBUG org.hibernate.jdbc.ConnectionManager  - connection already null in cleanup : no action
2372 [main] DEBUG org.hibernate.jdbc.ConnectionManager  - connection already null in cleanup : no action
2372 [main] DEBUG org.hibernate.jdbc.ConnectionManager  - connection already null in cleanup : no action
2372 [main] DEBUG org.hibernate.jdbc.ConnectionManager  - connection already null in cleanup : no action

por essa ultima linha, acho que está tendo algum problema na conexão.
Alguém pode me ajudar?

lordtiago

No seu controller vc abriu a sessão assim neh:

em = getEntityManager(); em.getTransaction().begin();
e depois está dando o commit?

Se sim, verifique no depurador, se o comando está recebendo o objeto paciente.
Seu xml com a configuração do Banco de Dados está correto?

M

Oi lordtiago,

cara eu consegui resolver. Eu fiz:

this.entityManager.remove(this.entityManager.merge(object));

tiver que fazer um merge no object que veio do banco para poder remover, não sei porque mas dessa forma funcionou.

lordtiago

Entity Merge Method
Detached entities have a persistent identity in the database, but are not in the current persistence context. That situation will exist if you have created a Player from a previously serialized file or if you have either cleared or closed the entity manager. You can update the entity and merge it back into the persistence context with the merge method.

The following code demonstrates how to change the Team assignment of a detached entity. The Player instance is detached from the persistence context once you call the entity manager’s clear method. Also, entities become detached when you close the entity manager. The entity is still in the database, yet the entity manager no longer actively manages it.

// The EntityManager, em, already exists for this example.
...
// We just happen to know that '5' is one of the
// player identifiers. You shouldn't normally hard-code this
// into any application.
Player p = em.find(Player.class, 5L);
em.clear();
// p is now detached for the convenience of this example

Team t = new Team("Ventura Surfers", "National");
p.setTeam(t);

em.getTransaction().begin();
Player managedPlayer = em.merge(p);
em.getTransaction().commit();

The merge command places the detached object back into the managed state. Additionally, the command returns a managed copy of the entity.

Como diz no artigo tecnico da Sun http://java.sun.com/developer/technicalArticles/J2SE/Desktop/persistenceapi/

Criado 14 de agosto de 2010
Ultima resposta 17 de ago. de 2010
Respostas 6
Participantes 2