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();
}
}
}
outputCode:
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.