-->
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.  [ 2 posts ] 
Author Message
 Post subject: subclass and _javassist_ classes
PostPosted: Tue Aug 09, 2011 4:17 am 
Newbie

Joined: Tue Aug 09, 2011 3:26 am
Posts: 2
Hi.

When loading objects (Link,Host,Socket,Program...), the heirs of the super class (CheckObject) in a single Hibernate session, _some_ of the objects instead of native class return class.simpleClassName = CheckObject_$$_javaassist_19. In this case no Exception.

Code:
public List<CheckObject> findRootCheckObjects() {
    HibernateTemplate session = getHibernateTemplate();
    List<CheckObject> list = session.find( "select o from CheckObject o where o.parent=null" );
    // lazy - true
    for (CheckObject checkObject : list) {
    findResurce_lazy_checkobject( checkObject );
    }
    return list;
}

/**  * @param checkObject
*/
private void findResurce_lazy_checkobject( CheckObject checkObject ){
    if( checkObject.getParent() instanceof Link){
    return;
    }
    getHibernateTemplate().initialize( checkObject );
    for (CheckObject element : checkObject.getChildrens()) {
    findResurce_lazy_checkobject (element);
    }
}


The reason for this class of objects Link and propery "link" , which refers to any subclass CheckObject.

If Link@link refers to an object, the object becomes CheckObject_$$_javaassist :(.

How to get hibernate boundaries require the original class of CheckObject_$$_javaassist ?

For example, when an object is passed through the RMI, he gets the original class(!) on client side, not CheckObject_$$_javaassist.

Example data:
Host1
:---> Socket1 (class CheckObject_$$_javaassist)
:---> Socket2 (class Socket)
:---> Socket3 (class Socket)

Host2
:---> Program1
:---> Link1 (@link=Socket1)

Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
        "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping package='ru.stb.sharov.monitor.check.domain'>
   
    <class name="CheckObject" table='monitorCheckObject'  >

      <id name="id" column="id" unsaved-value="0" >
          <generator class="org.hibernate.id.enhanced.SequenceStyleGenerator">
         <param name="sequence_name">monitorid_check_object</param>
         <param name="initial_value">100</param>
          </generator>
      </id>

      <discriminator type="string"  />
      
      <many-to-one name="parent" column="parent_id" /> <!--  lazy="false"  -->

      <list name="childrens" cascade="all" > <!--  lazy="false"  -->
           <key column="parent_id"/>
          <list-index column="child_index"/>
          <one-to-many class="CheckObject"/>
      </list>

      <property name='name'/>
      <property name='enterPassword'/>
      <property name='tested'/>

<!--    <property name='status'/>
      <many-to-one name="status" column="status_id"  />
-->   
      <subclass name="Root"   lazy="false"  discriminator-value="root" >
      </subclass>

      <subclass name="Section"   lazy="false"  discriminator-value="section" >
      </subclass>

      <subclass name="Module"   lazy="false"  discriminator-value="module" >
      </subclass>
      
      <subclass name="Host"  lazy="false"  discriminator-value="host" >
           <property name='ip' />
      </subclass>
   
      <subclass name="GroupIt"  discriminator-value="groupIt"  lazy="false"  >
      </subclass>
      
      <subclass name="Program"  discriminator-value="app"  lazy="false"  >
      </subclass>
      
      <subclass name="Socket"  discriminator-value="socket"  lazy="false"  >
           <property name='ip' />
           <property name='port' />
      </subclass>
      
      <subclass name="Jdbc"  discriminator-value="jdbc"  lazy="false"  >
           <property name='username' />
           <property name='password' />
           <property name='driverClassName' />
           <property name='url' />
           <property name='testSql' />
      </subclass>
      
      <subclass name="Rmi"  discriminator-value="rmi"  lazy="false"  >
           <property name='ip' />
           <property name='port' />
           <property name='serviceName' />
           <property name='testMethod' />
           <property name='testProperty' />
      </subclass>
      
      <subclass name="Soap"  discriminator-value="soap"  lazy="false"  >
           <property name='username' />
           <property name='password' />
           <property name='url' />
      </subclass>

      <subclass name="SoapSHSK"  discriminator-value="soap-shsk"  lazy="false"  >
           <property name='username' />
           <property name='password' />
           <property name='url' />
           <property name='nls' />
      </subclass>

      <subclass name="CorbaIask"  discriminator-value="jaguar"  lazy="false"  >
           <property name='username' />
           <property name='password' />
           <property name='url' />
      </subclass>

      <subclass name="Http"  discriminator-value="http"  lazy="false"  >
           <property name='trustStore' />
           <property name='trustStorePassword' />
           <property name='url' />
      </subclass>
      
      <subclass name="Link"  discriminator-value="connect"  lazy="false" >
         <many-to-one name="link" />
      </subclass>

    </class>



Code:
package ru.stb.sharov.monitor.check.domain;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import ru.stb.sharov.monitor.domain.IdBaseObject;

/** О..ект.
*
* @author sharov
*
*/
public class CheckObject extends IdBaseObject implements Serializable {
   
   protected String enterPassword;
   /** .аро.. .росмотра со.ер..мо.о ..емента. */
   public String getEnterPassword() {      return enterPassword;   }
   public void setEnterPassword(String enterPassword) {      this.enterPassword = enterPassword;   }

   protected String name;
   protected CheckObject parent;
   protected List<CheckObject> childrens = new ArrayList<CheckObject>();
   
   /** В.о.енн.е о..ект .роверк. */
   public List<CheckObject> getChildrens() {      return childrens;   }
   public void setChildrens(List<CheckObject> childrens) {      this.childrens = childrens;   }

   /** На.менован.е о..екта */
   public String getName() {      return (name==null?"": name);   }
   public void setName(String name) {      this.name = name;   }
   
   /** Сс..ка на ро..те..стк.. о..ект. */
   public CheckObject getParent() {      return parent;   }
   public void setParent(CheckObject parent) {      this.parent = parent;   }
   
   public String toString() {      return getTypeName()+" "+getName();   }
   
   /** Вернут. с..сок о...ок ва...а....
    * <li>key = .м. сво.ства.
    * <li>value = о...ка.
    * @return масс.в key,value
    */
   public HashMap<String, String> getValidateErrors(){
      return null;
   };
   
   /** Т... о...аем.х В.о.енн.х о..ектов (.ете.)
    * О.ре.е..ет как.е ра.ре.ен. о..ект. в {@link #getChildrens()}
    * */
   public CheckObject[] getTypeChildrens(){
      return null;
   };

   /** .м. т..а ..емента.
    * @return
    */
   public String getTypeName() {
      return this.getClass().getSimpleName();
   }

   /** .р..нак то.о, .то на о..ект мо.ет сое..н.т.с. с .ру..м. о..ектам. ({@link List}) */
   public boolean getLinked(){      return false;   }
   
   /** .р..нак то.о, .то о..ект мо.ено .а...ат. .аро.ём */
   public boolean getSecured(){      return false;   }
   
   /** Ну.но .. на.менован.е */
   public boolean getNamed(){      return true;   }
   
   /** Тест.роват. ... нет.
    * Мо.но вк....т. . в.к....т. вру.ну.
    * */
   private Boolean tested = getNeedTested();
   public Boolean getTested() {
      return (tested==null?false:tested);   
   }
   public void setTested(Boolean tested) {      this.tested = tested;   }
   
   
   /** Ну.но .. тест.рован.е */
   public Boolean getNeedTested() {      return false;   }
   
   
   private Status status;
   public Status getStatus() {      return status;   }
   public void setStatus(Status status) {      this.status = status;   }
   
}

Code:
package ru.stb.sharov.monitor.check.domain;

import java.util.HashMap;


/** Сое..нен.е с .ру..м. о..ектам..
*
* @author sharov
*
*/
public class Link extends CheckObject{
   CheckObject link;

   /** сс..ка на о..ект с котор.м сое..н.етс. ..емент.
    * @return
    */
   public CheckObject getLink() {      return link;   }
   public void setLink(CheckObject link) {      this.link = link;   }

   @Override
   public String toString() {
      try {
         return getName()+"[link="+link+"]";
      } catch (Exception e) {
         return getName();
      }
   };

   @Override
   public CheckObject[] getTypeChildrens() {
      return new CheckObject[]{};
   }
   
   public String getTypeName() {
      return "Св...";
   }

   @Override
   public HashMap<String, String> getValidateErrors() {
      HashMap<String, String> errors = new HashMap<String, String>();   
      if(link == null){
         errors.put("link", "Не в..ран о..ект ... сое..нен.." );
      }
      if(link == this ){
         errors.put("link", "Не.... в..рат. сое..нен.е с сам.м со.о." );
      }
      return errors;
   }
   @Override
   public boolean getLinked() {
      return false;
   }
   
   @Override
   public boolean getNamed() {
      // TODO Auto-generated method stub
      return false;
   }

}

Code:
package ru.stb.sharov.monitor.check.domain;

import java.util.HashMap;

/** Серв.с т..а Socket.
* @author sharov
*/
public class Socket extends Host {
   int port;
   /** .орт сокета */
   public int getPort() {      return port;   }
   public void setPort(int port) {      this.port = port;   }
   
   @Override
   public String getIp() {
      String parentIp = findParentIp( parent );
      return ( parentIp==null? super.getIp() : parentIp) ;
      //return getIp();
   }

   private static CheckObject[] socketTypeChildrens = {
      new Link()
   }; 
   
   public CheckObject[] getTypeChildrens() {
      return socketTypeChildrens;
   }

   public String getTypeName(){      return "Серв.с";   }

   @Override
   public String toString() {
      return super.toString()+"[port=" + port + "]";
   }

   @Override
   public HashMap<String, String> getValidateErrors() {
      HashMap<String, String> errors = super.getValidateErrors();   
      if(port<=0 ){
         errors.put("port", "Не ука.ан Port серв.са" );
      }
      return errors;
   }
   
   /** Нахо..т IP ро..те...
    * @param in - ро..те..ск.. о..ект
    * @return
    */
   private String findParentIp(CheckObject in){
      if( in==null) return null;
      if( in instanceof Host  ) return ((Host)in).getIp();
      else return findParentIp( in.parent );
   }

   public boolean getLinked(){      return true;   }
}

Code:
package ru.stb.sharov.monitor.check.domain;

import java.util.HashMap;

/** Сервер.
* @author sharov
*/
public class Host extends CheckObject{
   
   private String ip;
   
   public Host() {
      super();
   }

   private static CheckObject[] hostTypeChildrens = {
       new Rmi()
      ,new Program()
      ,new Socket()
      ,new Jdbc()
      ,new Soap()
      ,new Http()
      ,new CorbaIask()
      ,new SoapSHSK()
      ,new Module()
      ,new GroupIt()
   }; 
   
   public CheckObject[] getTypeChildrens() {
      return hostTypeChildrens;
   }

   /** IP А.рес сервера.
    * Ес.. не о.ре.е.ён, .ровер.ет о..ект ро..те.. {@link #getParent()}, ес.. .то {@link Host}, .ерёт е.о а.рес.
    */
   public String getIp() {      return this.ip;    }
   public void setIp(String ip) {   this.ip = ip;   }

   public String getTypeName(){      return "Сервер";   }
   
   public String toString() {      return super.toString()+" [ip=" + ip + "]";   }

   public HashMap<String, String> getValidateErrors() {
      HashMap<String, String> errors = new HashMap<String, String>();   
      if(ip==null || ip.equals("")){
         errors.put("ip", "Не ука.ан IP а.рес" );
      }
      return errors;
   }

   
   private int timeout = 5000;
   public int getTimeout() {      return timeout;   }
   public void setTimeout(int timeout) {      this.timeout = timeout;   }

   @Override
   public Boolean getNeedTested() {      return true;   }
   
   
}


Top
 Profile  
 
 Post subject: Re: subclass and _javassist_ classes
PostPosted: Wed Aug 10, 2011 2:04 am 
Newbie

Joined: Tue Aug 09, 2011 3:26 am
Posts: 2
Problem solved in several steps.
1. Added interfaces for all objects and "proxy='*Interfaces'" for class and subclass.
2. Got a bug in Link@setLink ((ClassCastException CheckObject and CheckObject_$$_javassist_*). Finally, although some error :).
Fixed bug not allowing the use of proxy, for "setLink".
Code:
<subclass name="Link"  discriminator-value="connect"  lazy="false" >
         <many-to-one name="link" lazy="false" />
  </subclass>

3. Removed interfaces added in (1) :).
That's it.

Thanks.


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