With only one HistoryEntry, one EForm, one EFormConf, and a few EFormConf approvers and admins; I get around 40 history entries listed for the one form. When my code creates and saves the objects, the database has the proper data, but when it loads it and I display it there are far too many HistoryEntries
Hibernate version: 3.1.1, annotations 3.1beta8
Mapping documents:
Code:
@Entity
public class HistoryEntry implements Serializable {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
protected long id;
@ManyToOne(cascade = CascadeType.ALL)
@JoinColumn(name="eform", insertable = false, updatable = false)
protected EForm eform;
protected String action;
...
}
@Entity
@Inheritance(strategy = InheritanceType.JOINED)
public class EForm implements Serializable {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
protected long id;
@ManyToOne
protected EFormConf conf;
@OneToMany(cascade=CascadeType.ALL, fetch = FetchType.EAGER)
@JoinColumn(name="eform")
@OrderBy("datetime")
protected List<HistoryEntry> history = new ArrayList<HistoryEntry>();
@Enumerated(EnumType.STRING)
protected Status status = Status.DRAFT;
@ManyToOne
protected Person creator;
...
}
@Entity
public class EFormConf implements Serializable {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
protected long id;
@Column(unique = true)
protected String name;
@ManyToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
@JoinTable(name="tblEFormConfApprovers")
@IndexColumn(name = "approval_order", base=1)
protected List<Person> approvers = new ArrayList<Person>();
@ManyToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
@JoinTable(name="tblEFormConfAdmins")
protected List<Person> admins = new ArrayList<Person>();
...
}
Code between sessionFactory.openSession() and session.close():Using spring hibernate support, I do:
Code:
form = getHibernateTemplate().get(MyForm.class, key);
where MyForm extends EForm, and key is a long
And then iterate through the HistoryEntries of
Code:
getForm().getHistory()
Name and version of the database you are using: MSSQL Server 8.0
The generated SQL (show_sql=true):
It's huge, joining between all tables. Our "Person" table has dozens of columns and is joined to several times.