Jean Cartier wrote:
Hi!, I have a simple class with the following xml,
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="credito.Agencia" table="T_Credito">
<id name="codigo" column="P_Codigo" type="long">
<generator class="assigned"/>
</id>
<property name="descripcion" column="A_Descripcion" type="string"/>
</class>
</hibernate-mapping>
I want to save-update this objects in the DB with the saveOrUpdate() method.
I know that I should use (for example) Interceptors because the generator class is "assigned",
but this strategy don't work for my scenario. For example, I wanto to do this:
....
Agencia a = new Agencia();
a.setCodigo(1234);
a.setDescripcion("Test");
session.saveOrUpdate(a); //Here, the insert works fine and Object 'a' is inserted in DB.
I don't understand how this can work. How does Hibernate know to generate INSERT instead of UPDATE for the first object? Could someone explain? thanks
Dmitry