Hi there,
I'm new to Hibernate and I'm trying to create an application to write on the DB a classic relationship one to many betweeen a Cliente and one or more Ordine. When I try to add a new cliente I get the following exception:
ERROR AbstractBatcher:73 - Exception executing batch:
org.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1 at org.hibernate.jdbc.Expectations$BasicExpectation.checkBatched(Expectations.java:85)
at org.hibernate.jdbc.Expectations$BasicExpectation.verifyOutcome(Expectations.java:70)
at org.hibernate.jdbc.BatchingBatcher.checkRowCounts(BatchingBatcher.java:90)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:70)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:268)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:268)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:188)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:51)
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 parkId.userProfiling.Prova.main(Prova.java:31)
This is Cliente.java
Code:
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"crmid",
"createDatetime",
"lastStatusChange",
"deleted",
"isParent",
"parentId",
"codiceCliente",
"tagid",
"nome",
"cognome",
"indirizzo",
"numeroCivico",
"citta",
"cap",
"prov",
"ordini"
})
@XmlRootElement(name = "Row")
public class Cliente {
@XmlElement(required = true)
protected int crmid;
@XmlElement(required = true)
@XmlJavaTypeAdapter(CollapsedStringAdapter.class)
@XmlSchemaType(name = "NMTOKEN")
protected String createDatetime;
protected Date createDatetimeDB;
@XmlElement(required = true)
protected String lastStatusChange;
protected Date lastStatusChangeDB;
@XmlElement(required = true)
protected int deleted;
@XmlElement(required = true)
protected int isParent;
@XmlElement(required = true)
protected int parentId;
@XmlElement(name = "CodiceCliente", required = true)
protected int codiceCliente;
@XmlElement(name = "TAGID", required = true)
protected String tagid;
@XmlElement(name = "Nome", required = true)
@XmlJavaTypeAdapter(CollapsedStringAdapter.class)
@XmlSchemaType(name = "NCName")
protected String nome;
@XmlElement(name = "Cognome", required = true)
protected String cognome;
@XmlElement(name = "Indirizzo", required = true)
protected String indirizzo;
@XmlElement(name = "NumeroCivico", required = true)
@XmlJavaTypeAdapter(CollapsedStringAdapter.class)
@XmlSchemaType(name = "NMTOKEN")
protected String numeroCivico;
@XmlElement(name = "Citta", required = true)
@XmlJavaTypeAdapter(CollapsedStringAdapter.class)
@XmlSchemaType(name = "NMTOKEN")
protected String citta;
@XmlElement(name = "CAP", required = true)
@XmlJavaTypeAdapter(CollapsedStringAdapter.class)
@XmlSchemaType(name = "NMTOKEN")
protected String cap;
@XmlElement(name = "Prov", required = true)
@XmlJavaTypeAdapter(CollapsedStringAdapter.class)
@XmlSchemaType(name = "NCName")
protected String prov;
@XmlElement(name = "Ordini", required = true)
protected Ordini ordini;
private Set<Ordine> setOrdini = new HashSet<Ordine>();
public Cliente(){
}
public int getCrmid() {
return crmid;
}
public void setCrmid(int value) {
this.crmid = value;
}
public String getCreateDatetime() {
return createDatetime;
}
public Date getCreateDatetimeDB() {
return createDatetimeDB;
}
public void setCreateDatetime(String value) {
this.createDatetime = value;
}
public void setCreateDatetimeDB(Date value) {
this.createDatetimeDB = value;
}
public String getLastStatusChange() {
return lastStatusChange;
}
public Date getLastStatusChangeDB() {
return lastStatusChangeDB;
}
public void setLastStatusChange(String value) {
this.lastStatusChange = value;
}
public void setLastStatusChangeDB(Date value) {
this.lastStatusChangeDB = value;
}
public int getDeleted() {
return deleted;
}
public void setDeleted(int value) {
this.deleted = value;
}
public int getIsParent() {
return isParent;
}
public void setIsParent(int value) {
this.isParent = value;
}
public int getParentId() {
return parentId;
}
public void setParentId(int value) {
this.parentId = value;
}
public int getCodiceCliente() {
return codiceCliente;
}
public void setCodiceCliente(int value) {
this.codiceCliente = value;
}
public String gettagid() {
return tagid;
}
public void settagid(String value) {
this.tagid = value;
}
public String getNome() {
return nome;
}
public void setNome(String value) {
this.nome = value;
}
public String getCognome() {
return cognome;
}
public void setCognome(String value) {
this.cognome = value;
}
public String getIndirizzo() {
return indirizzo;
}
public void setIndirizzo(String value) {
this.indirizzo = value;
}
public String getNumeroCivico() {
return numeroCivico;
}
public void setNumeroCivico(String value) {
this.numeroCivico = value;
}
public String getCitta() {
return citta;
}
public void setCitta(String value) {
this.citta = value;
}
public String getcap() {
return cap;
}
public void setcap(String value) {
this.cap = value;
}
public String getProv() {
return prov;
}
public void setProv(String value) {
this.prov = value;
}
public Ordini getOrdini() {
return ordini;
}
public void setOrdini(Ordini value) {
this.ordini = value;
}
public Set getSetOrdini() {
return setOrdini;
}
public void setSetOrdini(Set value) {
this.setOrdini=value;
}
}
This is his Ordine.java
Code:
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"idOrdine",
"bundle"
})
@XmlRootElement(name = "Ordine")
public class Ordine {
@XmlElement(name = "IdOrdine", required = true)
protected int idOrdine;
@XmlElement(name = "Bundle", required = true)
protected int bundle;
public Ordine(){
}
public int getIdOrdine() {
return idOrdine;
}
public void setIdOrdine(int value) {
this.idOrdine = value;
}
public int getBundle() {
return bundle;
}
public void setBundle(int value) {
this.bundle = value;
}
}
And this is the corresponding hbm.xml
Code:
<?xml version="1.0"?><!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="parkId.elements.anagCli">
<class name="Cliente" table="anagrafica_clienti">
<id name="codiceCliente" column="codiceCliente">
</id>
<property name="crmid"/>
<property name="createDatetimeDB" type="timestamp" />
<property name="lastStatusChangeDB" type="timestamp" />
<property name="deleted"/>
<property name="isParent"/>
<property name="parentId"/>
<property name="tagid"/>
<property name="nome"/>
<property name="cognome"/>
<property name="indirizzo"/>
<property name="numeroCivico"/>
<property name="citta"/>
<property name="cap"/>
<property name="prov"/>
<set name="setOrdini" table="ordini">
<key column="codiceCliente"/>
<one-to-many class="Ordine"/>
</set>
</class>
<class name="Ordine" table="ordini">
<id name="idOrdine" column="id_ordine">
</id>
<property name="bundle"/>
</class>
</hibernate-mapping>
And this is the main test:
Code:
public class Prova {
public static void main(String a[]) throws ParseException {
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
Cliente cliente = new Cliente();
cliente.setCodiceCliente(2);
cliente.setNome("222aaa");
cliente.setCognome("222bbb");
cliente.setCreateDatetimeDB(ParkIdUtils.stringToDate("2011-07-07 15:28:47"));
Ordine ordine = new Ordine();
ordine.setIdOrdine(1);
ordine.setBundle(11);
cliente.setSetOrdini(new HashSet());
cliente.getSetOrdini().add(ordine);
session.save(cliente);
session.getTransaction().commit();
session.close();
HibernateUtil.getSessionFactory().close();
}
}
It seems to me that I've done all the things explained in the different tutorials and I can't get a solution..
Can anyone help me?
Thanks in advance