0 Replies Latest reply on Nov 16, 2006 5:40 AM by hoeft

    Exceptions during persisting an entity

    hoeft

      Hi!

      I use JBOSS 4.0.5GA and get always following exception:

      11:06:47,445 WARN [JDBCExceptionReporter] SQL Error: 0, SQLState: null
      11:06:47,445 ERROR [JDBCExceptionReporter] failed batch
      11:06:47,445 ERROR [AbstractFlushingEventListener] Could not synchronize database state with session
      org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update
       at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103)
       at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91)
       at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
       at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:249)
      


      ... and I don't know why :-(.

      My local client Code:
       public void testMessage() throws Throwable {
       TestStarterRemote testStarter = getTestObject();
      
       // build messages
       for (int i = 0; i < 10; i++) {
      
       Message msg = new Message();
      
       // add properties to each message
       Set<Propertie> properties = new HashSet<Propertie>();
       for (int n = 0; n < 2; n++) {
       //i must set the id here, because I want to insert the property
       //into a hashset
       properties.add(new Propertie(n, "key" + n, "value" + n));
       }
      
       msg.setHeaderProperties(properties);
      
       // if i==1: an error is being thrown here
       msg = testStarter.merge(msg);
       }
       }
      


      The message class:

      @Entity
      @Inheritance(strategy = InheritanceType.JOINED)
      public class Message extends EntityWithIntId implements Serializable {
      
       private static final long serialVersionUID = 1L;
      
       private Set<Propertie> headerProperties = new HashSet<Propertie>();
      
       private long id;
      
       @Id
       @GeneratedValue(strategy = GenerationType.AUTO)
       public long getId() {
       return id;
       }
      
       public void setId(long id) {
       this.id = id;
       }
      
      
       public Message() {
       }
      
       @OneToMany(cascade = { CascadeType.ALL }, fetch = FetchType.EAGER)
       public Set<Propertie> getHeaderProperties() {
       return headerProperties;
       }
      
      
       public void setHeaderProperties(Set<Propertie> properties) {
       this.headerProperties = properties;
       }}
      


      My property class:
      @Entity
      public class Propertie extends EntityWithIntId implements Serializable {
      
       private static final long serialVersionUID = 1L;
      
       private String key;
      
       private Serializable value;
      
       private long id;
      
       public Propertie() {
       }
      
       public Propertie(long id, String key, Serializable value) {
       super();
       this.setKey(key);
       this.setValue(value);
       this.setId(id);
       }
      
       @Id
       @GeneratedValue(strategy = GenerationType.AUTO)
       public long getId() {
       return id;
       }
      
       public void setId(long id) {
       this.id = id;
       }
      
      (...)
      }
      
      


      And now, maybe the root of all my problems, the base class:
      public abstract class EntityWithIntId {
      
       public abstract long getId();
      
       /**
       * two entities are equal if they have the same class and the same id
       *
       * @see java.lang.Object#equals(java.lang.Object)
       */
       @Override
       public boolean equals(Object obj) {
       if (obj == null || !obj.getClass().equals(this.getClass())) {
       return false;
       }
       EntityWithIntId tmp = (EntityWithIntId) obj;
      
       return tmp.getId() == this.getId();
       }
      
       @Override
       public int hashCode() {
       return new Long(this.getId()).hashCode();
       }
      


      I set the id of the each properties object in my client. The id is autmatically generated if the propertie is persisted. Is that the root of my problem. Has hibernate a problem with that?

      Thanks for your help
      Meinert