Hello,
I am a developer of an application that use hibernate 4.1. I don’t know if what I am showing is an issue or is normal.
I have these hbm.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class dynamic-update="true" entity-name="Uds" name="it.infolog.sce.model.impl.UdsStandard" table="uds">
<id column="id" name="id" type="java.lang.Long">
<generator class="native"/>
</id>
<property column="codice" name="codice" not-null="true" type="java.lang.String"/>
<many-to-one column="id_carico" entity-name="Carico" fetch="join" lazy="false" name="carico"/>
</class>
</hibernate-mapping>
and:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class dynamic-update="true" entity-name="Carico" name="it.infolog.sce.model.impl.CaricoStandard" table="carico">
<id column="id" name="id" type="java.lang.Long">
<generator class="native"/>
</id>
<property column="codice" name="codice" not-null="true" type="java.lang.String"/>
</class>
</hibernate-mapping>
this classes:
public class CaricoStandard implements Carico{
private Long id;
private String codice;
public CaricoStandard() {}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getCodice() {
return codice;
}
public void setCodice(String codice) {
this.codice = codice;
}
}
and
public class UdsStandard implements Uds {
private Long id;
private String codice;
private Carico carico;
public UdsStandard() {}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getCodice() {
return codice;
}
public void setCodice(String codice) {
this.codice = codice;
}
public Carico getCarico() {
return carico;
}
public void setCarico(Carico carico) {
this.carico = carico;
}
}
Now, I don’t understand why this happen:
I create a new Carico
I invoke uds.setCarico setting the new Carico.
I execute the query “from Uds u where u.id = idOfUds” and the Carico is correct
If I execute “select u.carico from Uds u where u.id = idOfUds” I see the one before the set of new carico.
With the first hql hibernate hit the cache, but seems that with the second one it misses the cache because it loads the old value of uds.carico.
I expected that hibernate loaded uds and carico from cache, but this is not what happened, why?
thank you
Giuseppe