Hi,
I want to export one database contents into another.But i dont want to auto generate the ids.
I want to use the same ids of the previous database.
I have the same hbm file for both the databases.In one database i want auto increment and in other database i want to use the existing id.
i want to overcome this error:
Code:
org.springframework.orm.hibernate3.HibernateOptimisticLockingFailureException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1; nested exception is org.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1
My hbm is :
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>
<class name="com.bean.test" table="test" dynamic-insert="true" dynamic-update="true" >
<id name="restaurantId" type="java.lang.Long">
<column name="restaurant_id" />
<generator class="com.bean.commons.CustomIdGenerator" />
</id>
I tried using this:
Code:
import java.io.Serializable;
import org.hibernate.HibernateException;
import org.hibernate.engine.SessionImplementor;
import org.hibernate.id.IdentifierGenerator;
import org.hibernate.id.IdentifierGeneratorFactory;
import org.hibernate.persister.entity.EntityPersister;
public class CustomIdGenerator implements IdentifierGenerator
{
@Override
public Serializable generate(SessionImplementor sessionImplementor, Object object) throws HibernateException
{
try
{
System.out.println("in custom generator..."+object.getClass().getCanonicalName());
EntityPersister entityPersister = sessionImplementor.getEntityPersister("restaurantId", object);
Serializable id = entityPersister.getIdentifierGenerator().generate(sessionImplementor, "restaurantId");
System.out.println("id is "+id);
if(id == null)
{
return IdentifierGeneratorFactory.POST_INSERT_INDICATOR;
}
return id;
}
catch (Exception e)
{
System.out.println("in exception ");
System.out.println(e.getMessage());
return null;
}
}
}
If the object does not contain an id, use the autoincremented one else use the existing.
Where am i going wrong.
Please help.
Thanks in advance.
Regards,
Annuk