I really would like to be able to delete a record from a single table that has a composite primary key. Here is my code for the composite key(getters/setters omitted):
@Embeddable
public class MISExceptionStoreUploadControlPK implements Serializable {
/**
* Serializable class - generated UID
*/
private static final long serialVersionUID = -2589068978210044521L;
@Column(name="STORE_NO", nullable=false)
private String storeNo;
@Column(name="EXTRACT_TIME", nullable=false)
private String extractTime;
Here is my code for the Entity (getters/setters omitted):
@Entity
@Table(name="SDSUSER_OWNER.MIS_EXCEPTION_STORE_UPLD_CNTRL")
public class MISExceptionStoreUploadControl implements Serializable {
/**
* Serializable class - generated UID
*/
private static final long serialVersionUID = 545018012527944915L;
//@Id
@EmbeddedId
private MISExceptionStoreUploadControlPK misExceptionStoreUploadControlPK;
@Column(name="UNDER_EXTRACT_DAYS", nullable=true)
private Integer underExtractDays;
@Column(name="UNDER_WEIGHT_RESERVE", nullable=false)
private Integer underWeightReserve;
Here is the code for trying to delete a record:
// Retrieve session from Hibernate
Session session = sessionFactory.getCurrentSession();
MISExceptionStoreUploadControlPK recordToBeDeleted = (MISExceptionStoreUploadControlPK) session.load(MISExceptionStoreUploadControlPK.class, misExceptionStoreUploadControl.getMisExceptionStoreUploadControlPK());
session.delete(recordToBeDeleted);
This is the error I get: nested exception is org.hibernate.MappingException: Unknown entity: com.classifieds.beans.volumetrics.MISExceptionStoreUploadControlPK
Editing the 'delete' code to use MISExceptionStoreUploadControl object doesn't work either. I get an error, which says that MISExceptionStoreUploadControlPK object was expected.
If it helps - I can confirm that a simple retrieval of all the records from the table is working.
I would be grateful for some advice on this one...THANKS!
@Embeddableit means you can logically create two objects of the table hibernate created for you. That means the tables are not normalized. I would suggest to have a@OneToOnerelationship rather.