-->
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.  [ 2 posts ] 
Author Message
 Post subject: "Could not synchronize database state with session"
PostPosted: Thu Aug 09, 2007 4:00 pm 
Beginner
Beginner

Joined: Thu Aug 09, 2007 3:48 pm
Posts: 38
Hibernate version: 3.2
Mapping documents: hibernate.cfg.xml
Full stack trace of any exception that occurs:
09/08/2007 22:58:37 [ERROR] org.hibernate.util.JDBCExceptionReporter - failed batch
09/08/2007 22:58:37 [ERROR] org.hibernate.util.JDBCExceptionReporter - failed batch
09/08/2007 22:58:37 [ERROR] org.hibernate.event.def.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:253)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:237)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:144)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
...
Caused by: java.sql.BatchUpdateException: failed batch
at org.hsqldb.jdbc.jdbcStatement.executeBatch(Unknown Source)
at org.hsqldb.jdbc.jdbcPreparedStatement.executeBatch(Unknown Source)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:246)
... 69 more

Name and version of the database you are using: HSQLDB 1.8.0.7

The generated SQL (show_sql=true):
org.hibernate.SQL - insert into category_fieldprop (category_id, fieldprops_index, fieldProps_id) values (?, ?, ?)


Anyway i've got 2 entities: Category and FieldProp.
Category has a list of FieldProp and when i am adding one to another i get the above exception.

Here are the classes and the code that generates the exception:
Code:
@Entity
@Table(name = "category")
public class Category
{
   private Integer id = -1;
   private String name;
   private String icon;
   private Set<Item> items;
   private List<FieldProp> fieldProps;

   public Category()
   {
      this.items = new HashSet<Item>();
      this.fieldProps = new LinkedList<FieldProp>();
   }
   
   public Category(String name, String icon)
   {
      this();
      this.name = name;
      this.icon = icon;
   }

   @Id @GeneratedValue(strategy = GenerationType.AUTO)
   public Integer getId()
   {
      return id;
   }

   public void setId(Integer id)
   {
      this.id = id;
   }

   @Basic @Column(nullable = false)
   public String getName()
   {
      return name;
   }

   public void setName(String name)
   {      
      this.name = name;      
   }

   @Basic
   public String getIcon()
   {
      return icon;
   }

   public void setIcon(String icon)
   {      
      this.icon = icon;      
   }

   @CollectionOfElements(fetch = FetchType.EAGER)
   @IndexColumn(name = "items_index")   
   @Cascade(org.hibernate.annotations.CascadeType.ALL)
   public Set<Item> getItems()
   {
      return this.items;
   }

   public void setItems(Set<Item> items)
   {
      this.items = items;
   }

   @CollectionOfElements(fetch = FetchType.EAGER)
        @OrderBy("colOrder")
   @IndexColumn(name = "fieldprops_index")   
   @Cascade(org.hibernate.annotations.CascadeType.ALL)
   public List<FieldProp> getFieldProps()
   {
      return this.fieldProps;
   }

   public void setFieldProps(List<FieldProp> fieldProps)
   {
      this.fieldProps = fieldProps;
   }
}

@Entity @Table(name="fieldprop")
public class FieldProp
{   
   public static final int COL_ORDER_START_INDEX = 1;

   private Integer id = -1;
   private String name;
   private String type;
   private String prefs;
   private boolean mandatory;
   private int colOrder;
   private boolean listVisible;
   
   public FieldProp()
   {
      this.init(null, null, null, false, COL_ORDER_START_INDEX, false);
   }

   public FieldProp(int colOrder)
   {
      this.init(null, null, "Integer", false, colOrder, false);
   }

   public FieldProp(String name, String type, boolean mandatory, int colOrder)
   {
      this.init(null, name, type, mandatory, colOrder, false);
   }
   
   public FieldProp(FieldProp other)
   {
      this.init(other.id, other.name, other.type, other.mandatory,
              other.colOrder, other.listVisible);
   }
   
   private void init(Integer id, String name, String type, boolean mandatory,
                 int colOrder, boolean isListVisible)
   {
      this.id = id;
      this.name = name;
      this.type = type;
      this.mandatory = mandatory;
      this.colOrder = colOrder;
      this.listVisible = isListVisible;
      this.colOrderChangedBroadcaster = new ChangeBroadcaster();
   }

   @Id @GeneratedValue(strategy=GenerationType.AUTO)
   public Integer getId()
   {
      return this.id;
   }

   private void setId(Integer id)
   {
      this.id = id;
   }

   @Basic @Column(nullable = false)
   public String getName()
   {
      return this.name;
   }

   public void setName(String name)
   {
      this.name = name;
   }

   @Basic @Column(nullable = false)
   public String getType()
   {
      return this.type;
   }

   public void setType(String type)
   {
      this.type = type;
   }

   @Basic
   public String getPrefs()
   {
      return this.prefs;
   }

   public void setPrefs(String prefs)
   {      
      this.prefs = prefs;      
   }
   
   @Basic @Column(nullable = false)
   public boolean getMandatory()
   {
      return this.mandatory;
   }
   
   public void setMandatory(boolean bMandatory)
   {
      this.mandatory = bMandatory;      
   }
   
   @Basic @Column(nullable = false)
   public int getColOrder()
   {
      return this.colOrder;
   }
   
   public void setColOrder(int colOrder)
   {
      this.colOrder = colOrder;      
   }
   
   @Basic @Column(nullable = false)
   public boolean getListVisible()
   {
      return this.listVisible;
   }
   
   public void setListVisible(boolean newListVisible)
   {      
      this.listVisible = newListVisible;      
   }
}

public static void addFieldProps(Category category, Set<FieldProp> fieldProps)
{
Session session = HibernateUtil.getSession();
      session.beginTransaction();
      for (FieldProp fieldProp : fieldProps)
         session.save(fieldProp);      
      category.getFieldProps().addAll(fieldProps);
      session.update(category);      
      session.getTransaction().commit();
}


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 13, 2007 2:21 am 
Beginner
Beginner

Joined: Thu Aug 09, 2007 3:48 pm
Posts: 38
bump


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.