Hi,
Using the Hibernate API, I am trying to delete an object which contains a composite id which is assigned. The composite id has a <key-many-to-one> relationship to the master table.
I need help on how to set the individual identifier value fields in the POJO corresponding to the table.
The code I am using is generic as follows:-
try
{
//table mapped object or POJO
model = Class.forName(classObj.getName()).newInstance();
PersistentClass persistClass = cfg.getClassMapping(classObj);
EntityPersister persister = new EntityPersister(persistClass,(SessionFactoryImpl)sessionObj.getSessionFactory());
String[] identityColumns = persister.getIdentifierColumnNames();
for(int i=0;i<identityColumns.length;i++)
{
//this is app specific data structure. Each pkValue represents value of individual primary key fields.
pkValue = entity.getProperty(identityColumns[i],null);
//unsure about this part. What to do here ???
persister.setPropertyValue(persistClass,identityColumns[i],pkValue);
}
sessionObj.delete(persistClass);
}
|