-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: Take a "photogragh" for an POJO with aGiveDate
PostPosted: Thu Nov 10, 2005 7:51 am 
Beginner
Beginner

Joined: Mon Sep 27, 2004 11:51 pm
Posts: 22
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


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 10, 2005 7:56 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
you can use Interceptor.instantiate() to do your own construction,
but hibernate still needs to set the values afterwards because of hibernates 2-phase loading.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 10, 2005 8:06 am 
Beginner
Beginner

Joined: Mon Sep 27, 2004 11:51 pm
Posts: 22
oh , sorry , l don't understand.

do l need to pass an aGiveDate as an arg like Interceptor.instantiate(..,aGiveDate) ? although l knew that it is not possible with the Interceptor API , otherwise l have to do

Code:
public Object instantiate( String entityName, EntityMode entityMode, Serializable id ) {
..... Date now = new Date();
}


but this will get different date , right ?

moon


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 10, 2005 8:21 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
as i said, not possible since we still need to set the values after the constructors is called.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 10, 2005 10:44 am 
Beginner
Beginner

Joined: Mon Sep 27, 2004 11:51 pm
Posts: 22
oh , ic , thanks. :)

but don't you think that it is nice feature if we have a lot status-info flag to display , this will avoid a lot of manual calculate code in other places ...
(may be there is difficulty to implement it .. :) )

moon


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.