Hi all!!
I'm getting a weird error and, after find on google and hibernate forums, I can't find any solution.
Here my codes:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="org.sgg.core.hibernate">
<class name="Asistencia" table="asistencia">
<id name="ID" type="long">
<column name="as_id"/>
<generator class="identity"/>
</id>
<property name="ClienteID" type="long">
<column name="as_cl_id"/>
</property>
<property name="EmpleadoID" type="long">
<column name="as_em_id"/>
</property>
<property name="FechaEntrada" type="long">
<column name="as_fecha_entrada"/>
</property>
<property name="HoraEntrada" type="long">
<column name="as_hora_entrada"/>
</property>
<property name="FechaSalida" type="long">
<column name="as_fecha_salida"/>
</property>
<property name="HoraSalida" type="long">
<column name="as_hora_salida"/>
</property>
<property name="UsrName" type="string">
<column name="as_usr_name"/>
</property>
</class>
</hibernate-mapping>
Object (Asistencia) class:
Code:
public class Asistencia extends ElementImpl {
private Long asId;
private Long asClId;
private Long asEmId;
private String usrName;
private Long asFechaEntrada;
private Long asHoraEntrada;
private Long asFechaSalida;
private Long asHoraSalida;
public Asistencia() {
}
public Asistencia(Long asClId, Long asEmId, Long asEntrada, Long asSalida) {
this.asClId = asClId;
this.asEmId = asEmId;
this.asFechaEntrada = asEntrada;
this.asFechaSalida = asSalida;
}
public Long geID() {
return this.asId;
}
public void setID(Long value) {
this.asId = value;
}
public Long getClienteID() {
return this.asClId;
}
public void setClienteID(Long value) {
this.asClId = value;
}
public Long getEmpleadoID() {
return this.asEmId;
}
public void setEmpleadoID(Long value) {
this.asEmId = value;
}
public Long getFechaEntrada() {
return this.asFechaEntrada;
}
public void setFechaEntrada(Long value) {
this.asFechaEntrada = value;
}
public Long getHoraEntrada() {
return this.asHoraEntrada;
}
public void setHoraEntrada(Long value) {
this.asHoraEntrada = value;
}
public Long getFechaSalida() {
return this.asFechaSalida;
}
public void setFechaSalida(Long value) {
this.asFechaSalida = value;
}
public Long getHoraSalida() {
return this.asHoraSalida;
}
public void setHoraSalida(Long value) {
this.asHoraSalida = value;
}
public void setUsrName(String usrName) {
this.usrName = usrName;
}
public String getUsrName() {
return usrName;
}
public int hashCode() {
return this.getID().hashCode();
}
@Override
public boolean equals(Object asis)
{
Asistencia a = (Asistencia) asis;
return a.getID().equals(getID());
}
public String toStringDebug() {
return null;
}
public String toString() {
//String s = "(ID: "+getID()+") ";
// if (getClienteID() != null)
// s += "PersonaID:" + getClienteID();
// if (getEmpleadoID() != null)
// s += "PersonaID:" + getEmpleadoID();
//return s;
return String.valueOf(getID());
}
}
Exception:
Code:
org.hibernate.HibernateException: identifier of an instance of org.sgg.core.hibernate.Asistencia was altered from 1 to null
at org.hibernate.event.def.DefaultFlushEntityEventListener.checkId(DefaultFlushEntityEventListener.java:85)
at org.hibernate.event.def.DefaultFlushEntityEventListener.getValues(DefaultFlushEntityEventListener.java:190)
at org.hibernate.event.def.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:147)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:219)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:99)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:50)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1216)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:383)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:133)
at org.sgg.core.db.Adapter.endTransaction(Adapter.java:82)
at org.sgg.core.db.Adapter.addElement(Adapter.java:141)
at org.sgg.core.handlers.CheckinHandler$2.actionPerformed(CheckinHandler.java:72)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
CheckinHandler.ActionPerformed:
Code:
public static ActionListener getIngresaHandler(final TabCheckin tabCheckin)
{
return new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
try {
Asistencia asis = tabCheckin.getAsistencia(TabCheckin.ACTION_INGRESA);
ElementImpl c = tabCheckin.getSelected();
if (c instanceof Cliente)
asis.setClienteID(c.getID());
else if (c instanceof Empleado)
asis.setEmpleadoID(c.getID());
asis.setUsrName(c.getNombre());
asis.setFechaEntrada( tabCheckin.tFecha.getDate().getTime() );
asis.setHoraEntrada( tabCheckin.tHora.getDate().getTime() );
Adapter.getInstance().addElement(asis);
} catch (Exception e1) {
e1.printStackTrace();
}
}
};
}
getAsistencia method:
Code:
public Asistencia getAsistencia(int action) {
if (_asistencia == null)
_asistencia = new Asistencia();
mapAsistenciaTo(_asistencia, action);
return _asistencia;
}
mapAsistenciaTo method:
Code:
private void mapAsistenciaTo(Asistencia a, int action)
{
if (tFecha.getDate()!= null)
{
if (action == TabCheckin.ACTION_INGRESA)
a.setFechaEntrada(tFecha.getDate().getTime());
else if( action == TabCheckin.ACTION_SALE)
a.setFechaSalida(tFecha.getDate().getTime());
}
if (tHora.getDate() != null)
{
if (action == TabCheckin.ACTION_INGRESA)
a.setHoraEntrada(tHora.getDate().getTime());
else if( action == TabCheckin.ACTION_SALE)
a.setHoraSalida(tHora.getDate().getTime());
}
}
addElement Method:
Quote:
public void addElement(Element o) throws Exception
{
beginTransaction();
try
{
getSession().saveOrUpdate(o);
endTransaction(true);
}catch(HibernateException he)
{
endTransaction(false);
he.printStackTrace();
}
}
endTransaction method:
Code:
public synchronized void endTransaction(boolean commit)
{
if (commit)
_transaction.commit();
else
_transaction.rollback();
}
Need more data? Ask me please!
I tried a lot of hashCode and equals methods returns, a lot of ways to add element (save, saveOrUpdate, with data, without data, etcetera).
On my program, I have many items like Asistencia and have no this problem.
Anybody can help me?
Thanks in advance
Sorry for my long post and my english.
Regards Juan Pablo From Argentina