|
|
Re: How to create a history for a Many To Many relationship? [message #1014834 is a reply to message #1014831] |
Tue, 26 February 2013 15:05 |
Renso Lohuis Messages: 44 Registered: July 2012 |
Member |
|
|
I have an SessionCustomizer like this
public class HistorySessionCustomizer implements SessionCustomizer {
private static final String START_DATE = "START_DATE";
private static final String END_DATE = "END_DATE";
protected List<Class<?>> historyEntityList = new ArrayList<Class<?>>();
public HistorySessionCustomizer() {
buildHistoryEntityList();
}
public HistorySessionCustomizer() {
historyEntityList.add(Movie.class);
historyEntityList.add(Actor.class);
}
public void customize(Session session) throws Exception {
for (Class<?> clazz : historyEntityList) {
ClassDescriptor sourceDescriptor = session.getDescriptor(clazz);
customize(sourceDescriptor);
}
}
private void customize(ClassDescriptor sourceDescriptor) throws Exception {
String sourceTableName = (String) sourceDescriptor.getTableNames().get(sourceDescriptor.getTableNames().size() - 1);
String historyTableName = "TRACK_" + sourceTableName;
HistoryPolicy policy = new HistoryPolicy();
policy.addHistoryTableName(sourceTableName, historyTableName);
policy.addStartFieldName(START_DATE);
policy.addEndFieldName(END_DATE);
if (sourceDescriptor.getJavaClass() == Movie.class) {
policy.addHistoryTableName("MOVIE_ACTOR", "TRACK_MOVIE_ACTOR");
}
sourceDescriptor.setHistoryPolicy(policy);
}
}
I try to add the many to many policy to the sourceDescriptor from the Movie class, but that doesn't work (see exception in my previous post)
I don't know where to add the history policy from the manytomany table, since it doesn't have his own class.
[Updated on: Tue, 26 February 2013 15:06] Report message to a moderator
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03952 seconds