Hi,
Sorry I just started using Hibernate and can't get pass the first mission.
I can save (create) an entity bean, but I get this error when I try to update it. I don't understand why?
It crashes when I call commit on the transaction. The record gets successfully inserted into the database.
My configuration is auto-commit turned off
Any help is highly appreciated.
16:31:26,919 ERROR AbstractFlushingEventListener : Could not synchronize database state with session
org.hibernate.exception.GenericJDBCException: could not update: [hnz.biz.modules.dms.entitybean.DMMemo#2]
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:126)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:114)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2453)
at org.hibernate.persister.entity.AbstractEntityPersister.updateOrInsert(AbstractEntityPersister.java:2335)
at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2635)
at org.hibernate.action.EntityUpdateAction.execute(EntityUpdateAction.java:115)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:279)It happens when i call transaction.commit() after I successfully insert a record then trying to update it again.
This is my code:
Code:
Session session = HUtil.getCurrentSession();
session.beginTransaction();
DMMemo memo = new DMMemo();
session.save(memo);
memo.setRef("dm123456");
memo.setStatus("QUERY");
session.update(memo);
session.getTransaction().commit(); //- crashes here!
This is my entity class DMMemo:
Code:
@Entity
@Table(name = "DMMEMO")
public class DMMemo implements Serializable
{
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name = "DMMEMOID", updatable = false, nullable = false)
private Long memoId = null;
@Column(name="DMSTATUS",length=5, nullable = false)
private String status = "CREQD";
@Column(name="DMREF",length=20)
private String ref = null;
@OneToMany( targetEntity=DMItem.class,
cascade=CascadeType.ALL,
fetch=FetchType.EAGER)
@JoinColumn(name="DIMEMOID")
private Set<DMItem> items = new HashSet<DMItem>(0);//- another entity bean
***
}
Finally, this is my configuration:
Code:
<session-factory>
<!-- Database connection settings -->
<property name="connection.driver_class">com.ibm.as400.access.AS400JDBCDriver</property>
<property name="connection.url">******</property>
<property name="connection.autocommit">false</property>
<property name="hibernate.connection.isolation">0</property>
<property name="connection.pool_size">100</property>
<property name="dialect">org.hibernate.dialect.DB2Dialect</property>
<property name="current_session_context_class">thread</property>
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<property name="show_sql">true</property>
<mapping class="hnz.biz.modules.dms.entitybean.DMItem"/>
<mapping class="hnz.biz.modules.dms.entitybean.DMMemo"/>
</session-factory>