Reputation: 1092
I have an embedded composite key that consist of two column
@Embeddable
public static class PK implements Serializable {
private static final long serialVersionUID = 4049628068378058196L;
@Column(name="colA", length=32, nullable=false)
private String colA;
@Column(name = "colB", length=32, nullable=false)
private String colB;
//constructors/getters/setters
}
Is there any way I can delete a persistent object using only colB
value such as
Serializable id = new String(myColBValue);
Object persistentInstance = session.get(MyObject.class, id);
if (persistentInstance != null) {
session.delete(persistentInstance);
}
or do I have to resort to using HQL statement?
Upvotes: 2
Views: 362
Reputation: 2654
If you need 2 columns to identify MyObject, then providing just one won't be enough to lookup a unique result every time. Neither Session
nor EntityManager
provide the method you're looking for. You'll have to go with Criteria
or Query
.
Upvotes: 1