Hello,
this the first time I use Hibernate. I have a simple table, 2 columns, the primary key is a string. I have written the following mapping:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping
PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping package="it.pippo.imtterminalini.hibernate" schema="PIPPO">
<class dynamic-insert="true" dynamic-update="true" name="CartellinoEsistito" table="CARTELLINI_ESISTITI">
<id column="CARTELLINO" name="cartellino" >
<!generator class="native"/>
</id>
<property column="ANCORA_ESISTENTE" name="ancoraEsistente"/>
</class>
</hibernate-mapping>
and a class:
Code:
package it.pippo.imtterminalini.hibernate;
import java.io.Serializable;
public class CartellinoEsistito implements Serializable
{
/**
* This attribute maps to the column CARTELLINO in the CARTELLINI_ESISTITI table.
*/
protected String cartellino;
/**
* This attribute maps to the column ANCORA_ESISTENTE in the CARTELLINI_ESISTITI table.
*/
protected String ancoraEsistente;
/**
* Constructor
*
*/
public CartellinoEsistito()
{
}
/**
* Constructor
*
*/
public CartellinoEsistito(String cartellino, String ancoraEsistente)
{
this.cartellino = cartellino;
this.ancoraEsistente = ancoraEsistente;
}
/**
* Method 'getCartellino'
*
* @return java.lang.String
*/
public java.lang.String getCartellino()
{
return cartellino;
}
/**
* Method 'setCartellino'
*
* @param cartellino
*/
public void setCartellino(java.lang.String cartellino)
{
this.cartellino = cartellino;
}
/**
* Method 'getAncoraEsistente'
*
* @return "S" or "N" java.lang.String
*/
public java.lang.String getAncoraEsistente()
{
return ancoraEsistente;
}
/**
* Method 'setCartellino'
*
* @param ancoraEsistente "S" or "N"
*/
public void setAncoraEsistente(java.lang.String ancoraEsistente)
{
this.ancoraEsistente = ancoraEsistente;
}
}
Then, in java, I generate an object:
Code:
ce = new CartellinoEsistito("ABCDE", "S");
sessioneHb.save(ce);
However, here I get a ConstraintViolationException "could not insert".
Please notice that the only constraint in the table is the primary key, and there is no other row in the table with key "ABCDE".
Thank you in advance.