Prezados,
Vejam o meu problema, tenho uma tabela com chave composta a qual criei duas classes:
@Entity
@Table(name = "UNIT")
public class Unit implements Serializable {
@EmbeddedId()
private UnitPK id;
@Column(name = "NAME", nullable = true)
private String name;
@Column(name = "SUPPLIER_BUILD_STATE", nullable = true)
private String supplierBuildState;
@Column(name = "ESW", nullable = true)
private String esw;
@Column(name = "STATUS", nullable = true)
private String status;
@Column(name = "LAST_UPDATE", nullable = true)
@Temporal(TemporalType.DATE)
private Calendar lastUpdate;
set e getters
@Embeddable
public class UnitPK implements Serializable {
@ManyToOne()
private Shelf shelf;
private int slot;
public UnitPK() {
}
Meu dao generico
public class Dao<T> {
private Session session;
private Class persistenceClass;
public Class getPersistenceClass() {
return persistenceClass;
}
public Session getSession() {
return session;
}
public Dao(Session session, Class persistenceClass) {
this.session = session;
this.persistenceClass = persistenceClass;
}
public T load(int i) {
return (T) this.session.load(persistenceClass, i);
}
public void save(T t) throws DaoException {
try {
this.session.save(t);
} catch (HibernateException ex) {
throw new DaoException(ex.getMessage());
}
}
public void saveOrUpdate(T t) throws DaoException {
try {
this.session.saveOrUpdate(t);
} catch (HibernateException ex) {
throw new DaoException(ex.getMessage());
}
}
public void merge(T t) throws DaoException {
try {
this.session.merge(t);
} catch (HibernateException ex) {
throw new DaoException(ex.getMessage());
}
}
public void delete(T t) throws DaoException {
try {
this.session.delete(t);
} catch (HibernateException ex) {
throw new DaoException(ex.getMessage());
}
}
public void update(T t) throws DaoException {
try {
this.session.update(t);
} catch (HibernateException ex) {
throw new DaoException(ex.getMessage());
}
}
public List<T> listAll() {
return this.session.createCriteria(this.persistenceClass).list();
}
public List<T> listAll(int firstResult, int maxResult) {
Criteria criteria = session.createCriteria(this.persistenceClass);
criteria.setFirstResult(maxResult);
criteria.setMaxResults(maxResult);
return criteria.list();
}
public T loadByExample(T t) {
Criteria criteria = this.session.createCriteria(persistenceClass);
criteria.add(Example.create(t).enableLike(MatchMode.START).excludeZeroes());
return (T) criteria.uniqueResult();
}
public List<T> listByExample(T t) {
Criteria criteria = this.session.createCriteria(persistenceClass);
criteria.add(Example.create(t).enableLike(MatchMode.START).excludeZeroes());
return criteria.list();
}
}
Aqui onde eu chamo o meu método em outra classe para gravar os dados
for (Unit u : units) {
try {
HibernateCore.beginTransaction();
daoUnit.merge(u);
HibernateCore.commitTransaction();
} catch (DaoException ex) {
HibernateCore.rollbackTransaction();
Logger.getLogger(ThreadMilegateInventory.class.getName()).log(Level.SEVERE, null, ex);
}
}
Ja verifique que os meus objetos u estao vindo preenchidos, então pedi para que o hibernate mostrasse o sql gerado, o detalhe é que so vem um select e nao o insert, veja:
select
unit0_.shelf_IP as shelf7_5_0_,
unit0_.slot as slot5_0_,
unit0_.ESW as ESW5_0_,
unit0_.LAST_UPDATE as LAST3_5_0_,
unit0_.NAME as NAME5_0_,
unit0_.STATUS as STATUS5_0_,
unit0_.SUPPLIER_BUILD_STATE as SUPPLIER6_5_0_
from
UNIT unit0_
where
unit0_.shelf_IP=?
and unit0_.slot=?
Com isto não e gravado nada na base de dados, ja tentei o metodo save bem como tentei usar o flush. Outro detalhe é que esta dentro de uma thread este metodo.
Alguem sabe o que pode estar ocorrendo?
ATt,