Cache Problem - Saving Bank Data to Java System

2

I have a system developed in Java using JPA, Hibernate, Primefaces. When I write system registry it reflects in the MySQL database normally, so far OK, but when I do unlike the database (register or change) in the application with several F5 it does not update, always needing to restart tomcat. I know there is little information but does anyone know where I should start? Summarizing from the Java system to the MySQl bank everything ok, from the bank to the system does not update with 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");
}

DomainEntity class

@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

Routine class

@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

Person Class

@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

Class RunRoutine

@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
    
asked by anonymous 08.05.2015 / 20:36

2 answers

0

After thinking that I would need to annotate the model classes, I saw that the solution to my case was pretty simple, see:

In my persistence.xml just added:

<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect" />
<property name="hibernate.connection.autocommit" value="true"/>

Full Persistence stayed:

<persistence-unit name="rtin" transaction-type="RESOURCE_LOCAL">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>

    <class>meu dominio</class>

    <properties>
        <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect" />
        <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect" />
        <property name="hibernate.connection.autocommit" value="true"/>
        <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/rotinas_diman" />
        <property name="javax.persistence.jdbc.user" value="root" />
        <property name="javax.persistence.jdbc.password" value="root" />

    </properties>
    
21.05.2015 / 18:51
0

The changes are apparently not being reflected in the base because of the hibernate internal cache. Take a look at Item 6 of this article: link

    
13.05.2015 / 16:18