-->
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.  [ 3 posts ] 
Author Message
 Post subject: Hibernate 3 returns Null if the method is final
PostPosted: Tue May 31, 2005 6:07 am 
Newbie

Joined: Mon May 31, 2004 2:52 am
Posts: 11
Hi,

I am facing a problem with "final" getter methods. I have a model class with final getter and setter methods. After loading the object, when I call the get method, it is returning me null.

If I change the method to non-final, then I am getting the expected value. This was working perfectly fine with hibernate 2.

Can any body tell me the logic behind this ?

CODE
=======

Document document = (Document) session.load(new Long(100),Document.class);
System.out.println("toString :" +document);
System.out.println("DocumentNumber" + document.getDocumentNumber());


CONSOLE OUT
=========

Document : setDocumentNumber 111
toString :documentNumber 111 documentType AWBprefix 172docId 100
Document : getDocumentNumber null
DocumentNumbernull

Code:
package com.sample;

public class Document {

   private String documentNumber;
   private String documentType;
   private String prefix;
   private Long docId;

   public Document(){}

   public Document(String docNumber,String prefix){
      setDocumentNumber(docNumber);
      setDocumentType("AWB");
      setPrefix(prefix);
   }
   public final String getDocumentNumber(){
      System.out.println("Document : getDocumentNumber "+ documentNumber);
      return documentNumber;
   }

   public String  getDocumentType() {
      return documentType;
   }

   public String getPrefix() {
      return prefix;
   }

   public final void setDocumentNumber(String documentNumber) {
      System.out.println("Document : setDocumentNumber "+ documentNumber);
      this.documentNumber = documentNumber;
   }

   public void setDocumentType(String documentType) {
      this.documentType = documentType;
   }

   public void setPrefix(String prefix) {
      this.prefix = prefix;
   }

   public void setDocId(Long docId){
      this.docId = docId;
   }

   public Long getDocId(){
      return docId;
   }

   public String toString(){
      return "documentNumber "+ documentNumber +
      " documentType " + documentType +
      "prefix "+ prefix +
        "docId "+ docId;
   }
}



Top
 Profile  
 
 Post subject:
PostPosted: Tue May 31, 2005 1:10 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Perhaps reading the Hibernate documentation would be a good start?

final methods are not proxyable.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 01, 2005 12:12 am 
Newbie

Joined: Mon May 31, 2004 2:52 am
Posts: 11
Thanks for the help..!!!

It was working in Hibernate 2.1.6 . I just did a migration to Hibernate 3.0 and I am getting null pointers left and right.

I checked under http://www.hibernate.org/250.html( the migration guide) and nothing is mentioned over there.

How can a version upgrade result in such a big behavior change ? Any way I am happy that I have a solution


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.