-->
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.  [ 1 post ] 
Author Message
 Post subject: Narrowing proxy and LazyInitializationException
PostPosted: Fri Jun 08, 2007 6:34 pm 
Newbie

Joined: Tue Sep 12, 2006 6:06 pm
Posts: 15
I have a class hierarchy that represents a ContactMethod with two subclasses, EmailContactMethod and SmsContactMethod. The SmsContactMethod has a reference to a WirelessCarrier. They are mapped to the DB using the single table pattern.

When I try to access the SmsContactMethod I get the following error.

Is there a relationship between the narrowProxy warning and the LazyInitializationException? If so, what are possible causes?

Code:
Jun 8, 2007 5:09:46 PM org.hibernate.engine.StatefulPersistenceContext narrowProxy
WARNING: Narrowing proxy to class com.silversky.scheduler.domain.EmailContactMethod - this operation breaks ==
Jun 8, 2007 5:09:46 PM org.hibernate.engine.StatefulPersistenceContext narrowProxy
WARNING: Narrowing proxy to class com.silversky.scheduler.domain.SmsContactMethod - this operation breaks ==
Jun 8, 2007 5:10:04 PM org.springframework.ui.context.support.ResourceBundleThemeSource getTheme
INFO: Theme created: name 'theme', basename [theme]
Jun 8, 2007 5:10:35 PM org.hibernate.LazyInitializationException <init>
SEVERE: could not initialize proxy - the owning Session was closed
org.hibernate.LazyInitializationException: could not initialize proxy - the owning Session was closed
   at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:60)
   at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:111)
   at org.hibernate.proxy.pojo.cglib.CGLIBLazyInitializer.invoke(CGLIBLazyInitializer.java:140)
   at com.silversky.scheduler.domain.WirelessCarrier$$EnhancerByCGLIB$$1aa74151.getTextMessageEmailDomain(<generated>)
   at com.silversky.scheduler.domain.SmsContactMethod.getFullValue(SmsContactMethod.java:105)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)



Here are the persistent classes:

Code:
/**
* @hibernate.class
*       table="user_contact_method"
*       lazy="false
* @hibernate.discriminator
*      column="type"
*      type="string"
*/
public abstract class ContactMethod implements Serializable {

   public static String EMAIL_TYPE = "EMAIL";
   public static String SMS_TYPE = "SMS";

   private static final Long UNSAVED_VALUE = new Long(-1L);
   
   private Long key = UNSAVED_VALUE;
   private String basicValue;

   /**
    * Determines if a de-serialized file is compatible with this class.
    *
    * Maintainers must change this value if and only if the new version of this
    * class is not compatible with old versions. See Sun docs for <a
    * href=http://java.sun.com/j2se/1.3/docs/guide/serialization/spec/class.doc6.html> details. </a>
    *
    * Not necessary to include in first version of the class, but included here
    * as a reminder of its importance.
    */
   private static final long serialVersionUID = 1L;

   private static Set TYPES;
   
   static {
      TYPES = new HashSet();
      TYPES.add(EMAIL_TYPE);
      TYPES.add(SMS_TYPE);
//      TYPES.add(IM_TYPE);
   }
   
   public ContactMethod() {
   }

   public static Set getTypes(){
      return TYPES;
   }

   public static Set getTemplates(){
      Set templates = new HashSet();
      Iterator it = getTypes().iterator();
      while (it.hasNext()){
         templates.add(newContactMethod((String)it.next()));
      }
      return templates;
   }
   
   public static ContactMethod newContactMethod(String type){
      return newContactMethod(UNSAVED_VALUE, type);
   }
   
   public static ContactMethod newContactMethod(Long key, String type){
      ContactMethod contact = null;
      if (EMAIL_TYPE.equals(type)){
         contact = new EmailContactMethod(key);
      } else if (SMS_TYPE.equals(type)){
         contact = new SmsContactMethod(key);
      }
      return contact;
   }
   
   public abstract String getType();
   
   public void setBasicValue(String address) {
      this.basicValue = address;
   }

   /**
    * @hibernate.property length="45" not-null="true" column="basic_value"
    */
   public String getBasicValue() {
      return basicValue;
   }

   public String getFullValue() {
      return basicValue;
   }

   public void setKey(Long key) {
      this.key = key;
   }

   /**
    * @hibernate.id column="key_value" unsaved-value="-1" generator-class="native"
    *
    *  Hibernate will recognize only new objects with the key set to unsaved-value
    *  as candidates for persistence.  To differentiate between unsaved objects use
    *  UniqueKeyProvider.getNextNegativeKey() to get a unique key, then change these
    *  negative key values to unsaved-value just before saving to ensure that
    *  hibernate will assign a real key from the database.  Failure to do this can
    *  cause a TransientObjectException when saving the object.
    */
   public Long getKey() {
      return key;
   }

   public String getKeyString() {
      return getKey().toString();
   }

   public boolean equals (Object otherObj){
      ContactMethod inst = null;
      boolean eq = true;
      if (this == otherObj){
         eq = true;
      } else {
         if (otherObj == null){
            eq = false;
         } else {
            if (otherObj.getClass() == this.getClass()){
               inst = (ContactMethod) otherObj;
               eq = eq && ClassUtil.isEqual(inst.getType(), this.getType());
               eq = eq && ClassUtil.isEqual(inst.getBasicValue(), this.getBasicValue());
            } else {
               eq = false;
            }
         }
      }
      return eq;
   }   
   
   public String toString() {
      StringBuffer buffer = new StringBuffer();
      buffer.append(this.getClass().getName());
      buffer.append("([");
      buffer.append(getKey());
      buffer.append("] type: ");
      buffer.append(getType());
      buffer.append(" value: ");
      buffer.append(getBasicValue());
      buffer.append(")");
      return buffer.toString();
   }

   public int hashCode() {
      int hash = 1;
      hash = hash * 31 + (getType() == null ? 0 : getType().hashCode());
      hash = hash * 31 + (getBasicValue() == null ? 0 : getBasicValue().hashCode());
      return hash;
   }
   
   public abstract String getDescription();

   /**
    * Return true if this contact method requires a short-format message, such as
    * the 140-character limit for SMS text messages.
    */
   public abstract boolean isShortFormat();
}


Code:
/**
* @hibernate.subclass
*       discriminator-value="SMS" lazy="false
*/
public class SmsContactMethod extends ContactMethod implements Serializable {

   /**
    * Determines if a de-serialized file is compatible with this class.
    *
    * Maintainers must change this value if and only if the new version of this
    * class is not compatible with old versions. See Sun docs for <a
    * href=http://java.sun.com/j2se/1.3/docs/guide/serialization/spec/class.doc6.html> details. </a>
    *
    * Not necessary to include in first version of the class, but included here
    * as a reminder of its importance.
    */
   private static final long serialVersionUID = 1L;

   private WirelessCarrier wirelessCarrier;
   
   public SmsContactMethod() {
   }

   public SmsContactMethod(long key) {
      this(Long.valueOf(key));
   }

   public SmsContactMethod(Long key) {
      setKey(key);
   }

   public SmsContactMethod(String mobileNumber) {
      setBasicValue(mobileNumber);
   }

   public boolean equals (Object otherObj){
      SmsContactMethod inst = null;
      boolean eq = true;
      if (this == otherObj){
         eq = true;
      } else {
         if (otherObj == null){
            eq = false;
         } else {
            if (otherObj.getClass() == this.getClass()){
               inst = (SmsContactMethod) otherObj;
               eq = eq && ClassUtil.isEqual(inst.getType(), this.getType());
               eq = eq && ClassUtil.isEqual(inst.getBasicValue(), this.getBasicValue());
            } else {
               eq = false;
            }
         }
      }
      return eq;
   }   
   
   public String toString() {
      StringBuffer buffer = new StringBuffer();
      buffer.append(this.getClass().getName());
      buffer.append("([");
      buffer.append(getKey());
      buffer.append("] type: ");
      buffer.append(getType());
      buffer.append(" value: ");
      buffer.append(getBasicValue());
      buffer.append(")");
      return buffer.toString();
   }

   public int hashCode() {
      int hash = 1;
      hash = hash * 31 + (getType() == null ? 0 : getType().hashCode());
      hash = hash * 31 + (getBasicValue() == null ? 0 : getBasicValue().hashCode());
      return hash;
   }

   public String getDescription(){
      return "SMS Text Message";
   }

   /**
    * @param wirelessCarrier the wirelessCarrier to set
    */
   public void setWirelessCarrier(WirelessCarrier wirelessCarrier) {
      this.wirelessCarrier = wirelessCarrier;
   }

   /**
    * @hibernate.many-to-one column="wireless_carrier_key" lazy="false"
    */
   public WirelessCarrier getWirelessCarrier() {
      return wirelessCarrier;
   }
   
   public String getFullValue() {
      String addr = "";
      if (getWirelessCarrier() != null){
         addr = getBasicValue() + "@" + getWirelessCarrier().getTextMessageEmailDomain();
      }
      return addr;
   }
   
   public String getType() {
      return SMS_TYPE;
   }

   /**
    * @spring.validator type="required" msgvalue="Mobile number is required."
    *
    * Strip all non-numeric characters from the mobile number provided
    */
   public void setBasicValue(String mobileNumber) {
      String num = StringUtil.stripNonNumeric(mobileNumber);
      super.setBasicValue(num);
   }
   
   /**
    * Return true if this contact method requires a short-format message, such as
    * the 140-character limit for SMS text messages.
    */
   public boolean isShortFormat(){
      return true;
   }
   
}


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

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.