Eu tenho um sistema desenvolvido em Java usando JPA, Hibernate, Primefaces. Quando eu gravo cadastro do sistema reflete no banco de dados MySQL normalmente, até aqui OK, porém quando faço ao contrário do banco de dados(cadastro ou alteração) na aplicação com vários F5 ele não atualiza, sempre precisando reiniciar o tomcat. Sei que é pouca informação mas alguém sabe por onde eu devo começar? Resumindo do sistema Java para o banco MySQl tudo ok, do banco pra o sistema não atualiza com F5.
<?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="rtin">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>aqui esta o meu dominio</class>
<shared-cache-mode>NONE</shared-cache-mode>
<properties>
<property name="hibernate.cache.provider_class" value="org.hibernate.cache.SingletonEhCacheProvider" />
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect" />
<property name="hibernate.hbm2ddl.auto" value="update" />
<property name="hibernate.show_sql" value="false" />
<property name="hibernate.format_sql" value="true" />
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/teste" />
<property name="javax.persistence.jdbc.user" value="root" />
<property name="javax.persistence.jdbc.password" value="root" />
</properties>
</persistence-unit>
Request context:
public class RequestContext {
protected static final Logger logger = Logger.getLogger(RequestContext.class.getName());
protected Locale userLocale;
protected boolean replaceableSecurityContext = true;
protected EntityTransaction entityTransaction;
protected EntityManager entityManager;
/**
* Instanciação de ThreadLocal para manter o estado associado à thread
* corrente
*/
protected static ThreadLocal<RequestContext> instance = new ThreadLocal<RequestContext>() {
protected RequestContext initialValue() {
return null;
}
};
public RequestContext() {
this.entityTransaction = null;
this.entityManager = null;
}
public static RequestContext getCurrentInstance() {
if (instance.get() == null) {
throw new IllegalStateException(
"UserContext deve ser inicializado antes desde método ser invocado. Verifique a inicialização do UserContext.");
}
return instance.get();
}
public static void invalidateCurrentInstance() {
instance.set(null);
System.out.println("===== invalidated context");
}
public static void setupUserContext() {
RequestContext ctx = new RequestContext();
instance.set(ctx);
}
public void commitGlobalEntityTransaction() {
if (entityTransaction != null) {
if (entityTransaction.isActive()) {
entityTransaction.commit();
System.out.println("===== commited transaction");
}
entityTransaction = null;
}
}
public void rollbackGlobalEntityTransaction() {
if (entityTransaction != null) {
if (entityTransaction.isActive()) {
entityTransaction.rollback();
System.out.println("===== rolled back transaction");
}
entityTransaction = null;
}
}
public EntityTransaction resolveGlobalEntityTransaction() {
if (entityTransaction == null) {
EntityManager em = resolveDefaultEntityManager();
entityTransaction = em.getTransaction();
}
return entityTransaction;
}
public void beginGlobalEntityTransaction() {
if (!resolveGlobalEntityTransaction().isActive()) {
resolveGlobalEntityTransaction().begin();
System.out.println("===== began new transaction");
}
}
public EntityManager resolveDefaultEntityManager() {
if (entityManager == null) {
entityManager = PersistenceAgent.createDefaultEntityManager();
System.out.println("===== created entity manager");
}
return entityManager;
}
public void closeDefaultEntityManager() {
if (entityManager != null) {
entityManager.close();
entityManager = null;
}
System.out.println("===== closed entity manager");
}
Classe DomainEntity
@MappedSuperclass
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public abstract class DomainEntity implements Serializable {
private static final long serialVersionUID = 1L;
@Transient
protected String cannotEditReason;
@Transient
protected String cannotDeleteReason;
public abstract Long getId();
getters e setters equals e hashCode
Classe Rotina
@Entity
@Table(name = "rotina")
public class Rotina extends DomainEntity implements Serializable {
private static final long serialVersionUID = 1L;
@Id @GeneratedValue
private Long id;
private String nome;
getters e setters
Classe Pessoa
@Entity
@Table(name = "pessoa")
public class Pessoa extends DomainEntity implements Serializable {
private static final long serialVersionUID = 1L;
@Id @GeneratedValue
private Long id;
private String chave;
private String nome;
@OneToMany(mappedBy = "pessoaResponsavel")
private Collection<Rotina> rotinas = new ArrayList<Rotina>();
getters e setters
Classe ExecucaoRotina
@Entity
@Table(name = "execucao_rotina")
public class ExecucaoRotina extends DomainEntity implements Serializable {
private static final long serialVersionUID = 1L;
@Id @GeneratedValue
private Long id;
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "data_confirmacao_execucao")
private Date dataConfirmacaoExecucao;
@ManyToOne
private Rotina rotina;
getters e setters