Hi,
l want hibernate to instantiate my POJO (libraryUser) using a different (non-default) constructor , as well as it children - borrow , libraryUserType .
LibraryUser.java,
Code:
public class LibraryUser implements java.io.Serializable {
private Long id;
private Long version;
private String cardKey;
private String unifiedKey;
private Date admissionDate;
private Date expiryDate;
private Set reservations = new HashSet();
private Set libraryUserTypes = new HashSet();
private Set borrows = new HashSet();
private Set libraryUserBlocks = new HashSet();
private Set libraryUserFines = new HashSet();
// ************** flag or state-info ****************
private boolean dateExpired;
/** default constructor */
public LibraryUser() {
}
/** constructor with id */
public LibraryUser(Long id) {
this.id = id;
}
/******* my constructor with aGiveDate ******/
public LibraryUser(Date aGiveDate) {
this.dateExpired = isDateExpired(Date aGivenDate);
}
...
public boolean isDateExpired(Date aGivenDate) {
if (this.expiryDate.before(aGivenDate))
return true;
return false;
}
}
LibraryUser's child -->
Borrow.java ,
Code:
public class Borrow implements java.io.Serializable {
private Long id;
private Long version;
private Date borrowDate;
private Date dueDate;
private Date returnDate;
private Date reportlostDate;
private Date paidDate;
private int renewedNo;
private LibraryUserType libraryUserType;
private Item item;
private LibraryUser libraryUser;
private Set libraryUserFines = new HashSet();
// ************** flag or state-info ****************
private boolean overDue;
private Integer daysOfOverDue;
private BigDecimal fineAmount;
/** default constructor */
public Borrow() {
}
/** constructor with id */
public Borrow(Long id) {
this.id = id;
}
/** constructor with aGivenDate */
public Borrow(Date aGivenDate){
setOverDue(isOverDue(aGivenDate));
setDaysOfOverDue(calculateDaysOfOverDue(aGivenDate));
setFineAmount(calculateFineAmount());
}
...
}
similar for libraryUserType.
Question.
l want a libraryUser with borrows , libraryUserTypes fetching eagerly with a
same given date , how can l use Interceptor.instantiate(..) to get the libraryUser object graph ?
reference :
1. Constructor for new objects.
http://forum.hibernate.org/viewtopic.php?t=940809
2. defining constructor for hibernate-injection.
http://forum.hibernate.org/viewtopic.php?t=947081