-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: Error "was altered from X to null" no solution
PostPosted: Thu Jan 13, 2011 10:33 am 
Newbie

Joined: Thu Sep 23, 2010 11:14 am
Posts: 10
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


Top
 Profile  
 
 Post subject: Re: Error "was altered from X to null" no solution
PostPosted: Fri Jan 14, 2011 9:18 am 
Newbie

Joined: Thu Sep 23, 2010 11:14 am
Posts: 10
Nobody has solved this error?

Thanks in Advance


Top
 Profile  
 
 Post subject: Re: Error "was altered from X to null" no solution
PostPosted: Thu Jan 20, 2011 9:16 am 
Newbie

Joined: Thu Sep 23, 2010 11:14 am
Posts: 10
I see that nobody has this error or nobody has solved this error. So, it's a Hibernate bug? or it's a coding error?

If I can't solve this error, I'm obligated to go out from Hibernate because I need release a version and, I can't continue.

I'm so disapointed, I don't know if with this forum or with Hibernate.

Thanks a lot
Regards Juan Pablo


Top
 Profile  
 
 Post subject: Re: Error "was altered from X to null" no solution
PostPosted: Thu Jan 20, 2011 9:54 am 
Newbie

Joined: Thu Sep 23, 2010 11:14 am
Posts: 10
jotapdiez wrote:
I see that nobody has this error or nobody has solved this error. So, it's a Hibernate bug? or it's a coding error?

If I can't solve this error, I'm obligated to go out from Hibernate because I need release a version and, I can't continue.

I'm so disapointed, I don't know if with this forum or with Hibernate.

Thanks a lot
Regards Juan Pablo


After posting this, I got to try (once again) to find the error. Searching and searching I found the error. Want to know what was?
Simple. In parent class of Asistencia Object (the parent class is ElementImpl) getID returns null always because is only for standarize my objects with Nombre and ID.
So, in Asistencia class, I need overwrite getID to return the correct ID of Asistencia (if have) and, in the hashCode and Equals need to use this ID (Asistencia ID) too. If you see my code of Asistencia object, yo can see this:
Code:
   public Long geID() {
      return this.asId;
   }


What is wrong? The name of method need to be getID and I write geID (Whitout T).
Adding the T character solve my error.

I can see that nobody saw my code, then, nobody tried to help me.

Thanks a lot
Regards Juan Pablo


Top
 Profile  
 
 Post subject: Re: Error "was altered from X to null" no solution
PostPosted: Thu Jan 23, 2014 12:06 am 
Newbie

Joined: Thu Jan 23, 2014 12:00 am
Posts: 1
Although no one help you, but your experience really did me a great favor.
So, thanks for your valuable experience.

Sincerely,

Jing




Quote:
After posting this, I got to try (once again) to find the error. Searching and searching I found the error. Want to know what was?
Simple. In parent class of Asistencia Object (the parent class is ElementImpl) getID returns null always because is only for standarize my objects with Nombre and ID.
So, in Asistencia class, I need overwrite getID to return the correct ID of Asistencia (if have) and, in the hashCode and Equals need to use this ID (Asistencia ID) too. If you see my code of Asistencia object, yo can see this:
Code:
public Long geID() {
return this.asId;
}


What is wrong? The name of method need to be getID and I write geID (Whitout T).
Adding the T character solve my error.

I can see that nobody saw my code, then, nobody tried to help me.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.