Hi
i am new to hibernate an currently working on a private project. So please excuse if i still have trouble understanding some principles (which is, with this question, something i expect)...
My Problem:
I have 2 entities
- DataLabel
- DataFlags (the cardinality should be 1..*, not 1)
When i load the DataLabel element i only want to load the elements from DataFlags where the BaseLine matches and not all. Hence i wrote this code:
Code:
public class DataLabel {
...
@Transient
public DataFlag getFlags(final IBaseLine bl) {
DataFlag flags = storedFlags.get(bl);
if (flags == null) {
final String hql = "from DataFlag df where df.ref = :entityKey and df.baseLine = :baseline ";
final ISessionProvider sp = Services.getService(ISessionProvider.class);
final Session session = sp.getSession();
final Query query = session.createQuery(hql);
query.setInteger("entityKey", getEntityKey());
query.setInteger("baseline", bl == null ? null : bl.getId());
flags = (DataFlag) query.uniqueResult();
storedFlags.put(bl, flags);
}
return flags;
}
...
}
What i now want, that when i call save on DataLabel that all elements within the map storedFlags are also saved/deleted.
Is that possible? If yes, how? Or is there a better way to get only the elements i need from DataFlags?
Thanks
Matthias