-->
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: The .getClass() return Class wrong, return <entity>_$$
PostPosted: Thu Feb 05, 2009 2:46 pm 
Newbie

Joined: Tue Jul 12, 2005 2:46 pm
Posts: 13
Location: BS2
If you observe the output of execution of the TestCX class, you see an error to second user (Clayton) in return of method getClass().

See class com.ws.model.entities.Mensagem_$$_javassist_0, it's not corret,
the correct output is: class com.ws.model.entities.Mensagem

In Attachement contain an .rar file with my miniproject to demonstrate a error.
Execute Mainclass TestCX to see aa error.




Hibernate version: core 3.3.1GA

Mapping documents:

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

<hibernate-mapping package="com.ws.model.entities">
   <class name="Usuario">
      <id access="property" unsaved-value="undefined" name="idUsuario"
         type="long" column="idUsuario">
         <generator class="native">
            <param name="sequence">seqPkUsuario</param>
         </generator>
      </id>
      
      <property name="login" length="10" access="property"
         not-null="true" />
         
      <property name="password" length="30" access="property"
         not-null="true" />
         
      <bag inverse="true" access="property" name="mensagemList">
         <key column="idUsuarioRemetente" />
         <one-to-many class="Mensagem" />
      </bag>
      
      <bag inverse="true" access="property" name="mensagemDestinatarioList">
         <key column="idUsuarioDestinatario" />
         <one-to-many class="MensagemDestinatario" />
      </bag>
      
   </class>
</hibernate-mapping>



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

<hibernate-mapping package="com.ws.model.entities">
   <class name="MensagemDestinatario">
      <id access="property" unsaved-value="undefined" name="idMensagemDestinatario"
         type="long" column="idMensagemDestinatario">
         <generator class="native">
            <param name="sequence">seqPkMensagemDestinatario</param>
         </generator>
      </id>

      <many-to-one column="idMensagem" access="property" class="Mensagem"
         not-null="true" name="mensagem" />
      <many-to-one column="idUsuarioDestinatario" access="property"
         class="Usuario" not-null="true" name="usuarioDestinatario" />

   </class>
</hibernate-mapping>



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

<hibernate-mapping package="com.ws.model.entities">
   <class name="Mensagem">
      <id access="property" unsaved-value="undefined" name="idMensagem"
         type="long" column="idMensagem">
         <generator class="native">
            <param name="sequence">seqPkMensagem</param>
         </generator>
      </id>
      <property name="message" length="4000" access="property"
         type="string" />
      <many-to-one column="idUsuarioRemetente" access="property"
         class="Usuario" name="usuarioRemetente" />
      <bag inverse="true" access="property" name="mensagemDestinatarioList">
         <key column="idMensagem" />
         <one-to-many class="MensagemDestinatario" />
      </bag>
   </class>
</hibernate-mapping>





Code between sessionFactory.openSession() and session.close():
Code:
package com;

import java.util.Iterator;
import java.util.List;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

import com.ws.model.entities.Usuario;

public class TestCX {
    public static void main(String[] args) {
   try {
       Configuration cfg = new Configuration().configure();
       SessionFactory factory = cfg.buildSessionFactory();
       Session session = factory.openSession();
      
       List lst = session.createCriteria(Usuario.class).list();
       Iterator it = lst.iterator();
       while (it.hasNext()) {
      
      Usuario u = (Usuario) it.next();
      System.out.println("\nUser: " + u.getLogin());
      List lg;

      System.out.println("List Message...");
      lg = u.getMensagemList();
      for (int x = 0; x < lg.size(); x++) {
          System.out.println(lg.get(x).getClass());
      }
      
      System.out.println("List MessageUser");
      lg = u.getMensagemDestinatarioList();
      for (int x = 0; x < lg.size(); x++) {
          System.out.println(lg.get(x).getClass());
      }

   
       }

   } catch (Exception e) {
       e.printStackTrace();
   }
    }
}



output
Code:

User: Albatrox
List Message...
class com.ws.model.entities.Mensagem
class com.ws.model.entities.Mensagem
List MessageUser
class com.ws.model.entities.MensagemDestinatario
class com.ws.model.entities.MensagemDestinatario

User: Clayton
List Message...
[color=red][b]class com.ws.model.entities.Mensagem_$$_javassist_0
class com.ws.model.entities.Mensagem_$$_javassist_0[/b][/color]
List MessageUser
class com.ws.model.entities.MensagemDestinatario
class com.ws.model.entities.MensagemDestinatario

User: Jakovisk
List Message...
List MessageUser




Debug level Hibernate log excerpt:
"PostgreSQL 8.2.3 on i686-pc-mingw32, compiled by GCC gcc.exe (GCC) 3.4.2 (mingw-special)"


If you observe the output of execution of the TestCX class, you see an error to second user (Clayton) in return of method getClass().

See class com.ws.model.entities.Mensagem_$$_javassist_0, it's not corret,
the correct output is: class com.ws.model.entities.Mensagem

In Attachement contain an .rar file with my miniproject to demonstrate a error.
Execute Mainclass TestCX to see aa error.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 05, 2009 2:58 pm 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
This is how proxies work, eg. by subclassing your entity classes. It somewhat explained here: http://www.hibernate.org/hib_docs/v3/re ... ng-proxies


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.