Dear All,
sorry for question but I'm new.
I know that this issue was already discussing on forum around the web but I don't found solution to my web app.
I try to explain my situation:
I've a web app that have to view data from db tables that are updated from a 3rd part application (batch java)
When batch java runs, I don't see in real time the db changed but only after few minutes.
The goal is to retrieve the latest data from the web app in real time and not late.
What is the best solution?
This occurred also when I update directly from a client DB (like HeidiSQL);
This is my example:
Code:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- Database connection settings -->
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost/sku_sviluppo</property>
<property name="connection.username">test</property>
<property name="connection.password">test</property>
<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property>
<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.MySQLInnoDBDialect</property>
<!-- Enable Hibernate's automatic session context management -->
<property name="current_session_context_class">thread</property>
<!-- Disable the second-level cache -->
<property name="cache.provider_class">org.hibernate.cache.internal.NoCacheProvider</property>
<property name="hibernate.cache.use_second_level_cache">false</property>
<property name="hibernate.cache.use_query_cache">false</property>
<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>
<!-- Drop and re-create the database schema on startup -->
<property name="hbm2ddl.auto">update</property>
<mapping resource="it/ccc/sku/vo/AnagraficaCategorie.hbm.xml"/>
<mapping resource="it/ccc/sku/vo/AnagraficaSottocategorie.hbm.xml"/>
<mapping resource="it/ccc/sku/vo/AnagraficaProdotti.hbm.xml"/>
</session-factory>
</hibernate-configuration>
this is a my class, I don't insert the other class because are the same, changed the name and attribute only:
Code:
package it.ccc.sku.vo;
import java.io.Serializable;
public class AnagraficaCategorie implements Serializable{
private int pk_id_ct;
private String codice_categoria_ct;
private String descrizione_ct;
private AnagraficaChain fk_anagrafica_chain_pk_ct;
private String enable_ct;
private String changedEnabled;
public AnagraficaCategorie(){}
public AnagraficaCategorie(int pk_id_ct, String codice_categoria_ct,
String descrizione_ct, AnagraficaChain fk_anagrafica_chain_pk_ct) {
//super();
this.pk_id_ct = pk_id_ct;
this.codice_categoria_ct = codice_categoria_ct;
this.descrizione_ct = descrizione_ct;
this.fk_anagrafica_chain_pk_ct = fk_anagrafica_chain_pk_ct;
this.enable_ct = enable_ct;
this.changedEnabled = "false";
}
public String getChangedEnabled() {
return changedEnabled;
}
public void setChangedEnabled(String changedEnabled) {
this.changedEnabled = changedEnabled;
}
public int getPk_id_ct() {
return pk_id_ct;
}
public void setPk_id_ct(int pk_id_ct) {
this.pk_id_ct = pk_id_ct;
}
public String getCodice_categoria_ct() {
return codice_categoria_ct;
}
public void setCodice_categoria_ct(String codice_categoria_ct) {
this.codice_categoria_ct = codice_categoria_ct;
}
public String getDescrizione_ct() {
return descrizione_ct;
}
public void setDescrizione_ct(String descrizione_ct) {
this.descrizione_ct = descrizione_ct;
}
public AnagraficaChain getfk_anagrafica_chain_pk_ct() {
return fk_anagrafica_chain_pk_ct;
}
public void setfk_anagrafica_chain_pk_ct(
AnagraficaChain fk_anagrafica_chain_pk_ct) {
this.fk_anagrafica_chain_pk_ct = fk_anagrafica_chain_pk_ct;
}
public AnagraficaChain getFk_anagrafica_chain_pk_ct() {
return fk_anagrafica_chain_pk_ct;
}
public void setFk_anagrafica_chain_pk_ct(
AnagraficaChain fk_anagrafica_chain_pk_ct) {
this.fk_anagrafica_chain_pk_ct = fk_anagrafica_chain_pk_ct;
}
public String getEnable_ct() {
return enable_ct;
}
public void setEnable_ct(String enable_ct) {
this.enable_ct = enable_ct;
}
}
and this hbm:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="it.ccc.sku.vo.AnagraficaCategorie" table="tb_anagrafica_categorie_ct" lazy="false">
<cache usage="read-write"></cache>
<id
name="pk_id_ct"
type="int"
column="pk_id_ct"
length="9"
>
<generator class="native" />
</id>
<property
name="codice_categoria_ct"
type="string"
column="codice_categoria_ct"
length="25"
/>
<property
name="descrizione_ct"
type="string"
column="descrizione_ct"
length="45"
/>
<property
name="enable_ct"
type="string"
column="enable_ct"
length="1"
/>
<many-to-one name="fk_anagrafica_chain_pk_ct" column="fk_anagrafica_chain_pk_ct" class="it.ccc.sku.vo.AnagraficaChain"/>
</class>
</hibernate-mapping>
at the and this is the method that retrieve the list from tables:
Code:
public List getAllAnagraficaCategorie() {
System.out.println("AnagraficaCategorieHibernateDao start");
Session session = HibernateUtil.getSession();
try {
List<AnagraficaCategorie> anagraficalist = null;
session.beginTransaction();
anagraficalist = session.createQuery(
"from AnagraficaCategorie as e left join fetch e.fk_anagrafica_chain_pk_ct d").list();
if(anagraficalist.size()>0)
System.out.println("AnagraficaCategorieHibernateDao" + anagraficalist.get(1).getDescrizione_ct());
return anagraficalist;
} finally {
session.close();
System.out.println("AnagraficaCategorieHibernateDao end");
}
}