-->
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: getId() on entity map key doesn't pass through proxy object
PostPosted: Tue Jun 02, 2009 3:49 pm 
Newbie

Joined: Tue Mar 24, 2009 4:30 pm
Posts: 5
Hello,

I am using the below hibernate mapping, which defines a map, "widgetMapping". Using this mapping the data is properly persisted, but when it is retrieved and I try to get the ID of the SourceWidget, it returns null, even though the ID is indeed set. Under the debugger I was able to see that calling getId() did not hit the proxy object, but rather went directly to the domain object. When I called getName() it hit the proxy object and properly returned the name. Also, calling getId() on the value (TargetWidget) properly returns the ID. Any indication to what the issue is would be greatly appreciated.

Thanks in advance,
Ryan

hibernate mapping:
Code:
  <class
    name="AbstractThing"
    table="Thing" abstract="true" lazy="true">
    <id name="id" column="Id" type="string">
       <generator class="assigned" />
    </id>

    <discriminator column="Type" type="string" />
    <property name="type" column="Type" type="string"
      insert="false" update="false" />
    <property name="targetId" column="TargetId" type="string" />

    <subclass
      name="Thing1"
      discriminator-value="Thing1">
      <map name="widgetMapping" table="WidgetMapping" lazy="true">
        <key column="AbstractThingId" not-null="true" />
        <index-many-to-many column="SourceWidgetId"
          class="Widget" />
        <many-to-many column="TargetWidgetId"
          class="Widget" />
      </map>
    </subclass>
  </class>


relevant classes:
Code:
public class Thing1 extends AbstractThing {
  private Map<Widget, Widget> _widgetMapping;

  public Map<Widget, Widget> getWidgetMapping() {
    return _widgetMapping;
  }

  public void setWidgetMapping(Map<Widget, Widget> widgetMapping_) {
    _widgetMapping = widgetMapping_;
  }
}

public class Widget {
  protected Serializable _id;
  protected String _name;

  public final Serializable getId() {
    return _id;
  }

  public final void setId(Serializable id_) {
    _id = id_;
  }

  public String getName() {
    return _name;
  }

  public void setName(String name_) {
    _name = name_;
  }
}


usage code:
Code:
for (Widget sourceWidget : thing.getWidgetMapping().keySet()) {
  System.out.println(sourceWidget.getId());  // null and doesn't hit proxy object
  System.out.println(sourceWidget.getName()); // as expected
}


variable inspection:
Code:
sourceWidget   Widget$$EnhancerByCGLIB$$d5b4abba  (id=162)   
   _id   null   
   _name   null   
   _type   null   
   CGLIB$BOUND   true   
   CGLIB$CALLBACK_0   CGLIBLazyInitializer  (id=181)   
      componentIdType   null   
      constructed   true   
      entityName   "Widget"   
      getIdentifierMethod   Method  (id=185)   
      id   "cad5f6f76598444c8623d09e6df8283e"   
      initialized   true   
      interfaces   Class<T>[1]  (id=187)   
      overridesEquals   true   
      persistentClass   Class<T> (Widget) (id=124)   
      replacement   null   
      session   null   
      setIdentifierMethod   Method  (id=192)   
      target   Widget  (id=193)   
         _id   "cad5f6f76598444c8623d09e6df8283e"   
         _name   "FooBar"   
      unwrap   false   
   CGLIB$CALLBACK_1   null   
   CGLIB$CONSTRUCTED   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.