-->
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: Discriminator and logical relation
PostPosted: Thu Jun 01, 2006 8:44 am 
Newbie

Joined: Wed May 31, 2006 10:22 am
Posts: 2
Location: France
Hello...

I m trying to create a Class(codifObject) which all subclasses are in a single table using the descriminator column(type)
to differentiate the subclasses. In fact all subclasses represent the functional codifications of the application.

i.e:

package fr.caleasing.bt.model.codifobject;

import java.io.Serializable;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

import fr.caleasing.bt.model.BaseObject;

/**
* @author VERDIEFL
*/
public class CodifObject extends BaseObject implements Serializable {

private String code;
protected String type;
private String libelle;
private String flag;

public static final String TYPE_CODIF = "";

public CodifObject(){};

....
....

public String toString() {
return ToStringBuilder.reflectionToString(ToStringStyle.MULTI_LINE_STYLE);
}

public boolean equals(Object o) {
boolean result = false;

if (o == this) {
result = true;
}
else if (o instanceof CodifObject) {
if (getCode().equals(((CodifObject) o).getCode()) && getType().equals(((CodifObject) o).getType())) {
result = true;
}
}

return result;
}

public int hashCode() {
return getCode().hashCode() + getType().hashCode();
}
}


For the class codifObject mappings, I wrote this:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="fr.caleasing.bt.model.codifobject">
<class name="CodifObject" table="TMP_RF_CODIF">
<id name="code" column="CD_CODIF" />
<discriminator column="CD_TYP_CODIF" force="true" type="string" insert="false"/>
<property name="libelle" column="LIB_CODIF" />
<property name="flag" column="FLAG_ACTIF" />
<subclass name="Type" discriminator-value="TYPE" />
<subclass name="Civilite" discriminator-value="CIVI" />
<subclass name="NatureCorrespondant" discriminator-value="NATCOR" />
<subclass name="TypeVoie" discriminator-value="TYPVOI" />
<subclass name="Extension" discriminator-value="EXTVOI" />
<subclass name="Departement" discriminator-value="DEPT" />
<subclass name="ApeNAF" discriminator-value="NAF" />
<subclass name="BAFI" discriminator-value="BAFI" />
<subclass name="ConsolidComptable" discriminator-value="CCPT" />
<subclass name="Statut" discriminator-value="STATUT" />
<subclass name="MotifInterdRole" discriminator-value="INTROL" />
<subclass ... />
<subclass ... />
</class>
</hibernate-mapping>


So codifObject has 41 subclasses and here two examples of subclasses of codifObject(MotifInterdRole,Statut):

/************** Example 1
*/
package fr.caleasing.bt.model.codifobject;
public class MotifInterdRole extends CodifObject{

public static final String TYPE_CODIF = "INTROL";

public MotifInterdRole(){
this.type = TYPE_CODIF;
}

public boolean equals(Object o) {
boolean result = false;

if (o == this) {
result = true;
}
else if (o instanceof MotifInterdRole) {
if (getType().equals(((MotifInterdRole) o).getType()) && getCode().equals(((MotifInterdRole) o).getCode())) {
result = true;
}
}

return result;
}

public int hashCode() {
return getCode().hashCode() + getType().hashCode();
}

}

/************** Example 2
*/
package fr.caleasing.bt.model.codifobject;

public class Statut extends CodifObject {

/*private String type;*/
public static final String TYPE_CODIF = "STATUT";

// Builder
public Statut (){
this.type = TYPE_CODIF;
}

public boolean equals(Object o) {
boolean result = false;

if (o == this) {
result = true;
}
else if (o instanceof Statut) {
if (getType().equals(((Statut) o).getType()) && getCode().equals(((Statut) o).getCode())) {
result = true;
}
}

return result;
}

public int hashCode() {
return getCode().hashCode() + getType().hashCode();
}


}


A simple use(reference into another class RoleTiers and mapping) of the two above subclasses is :

/**
*
*/
package fr.caleasing.bt.model.roles;

import java.io.Serializable;
import java.util.Date;
import java.util.Set;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

import fr.caleasing.bt.model.BaseObject;
import fr.caleasing.bt.model.codifobject.MotifInterdRole;
import fr.caleasing.bt.model.codifobject.Statut;


public class RoleTiers extends BaseObject implements Serializable {

private RoleKey key;
private MotifInterdRole motifInterd;
private Statut statut;
...
private Set metiersRoleList;
private Set commentairesRoleList;
....

// Builder
public RoleTiers(){
key = new RoleKey();
/** TODO */
motifInterd = new MotifInterdRole() ;
statut = new Statut() ;

}

......
.....

}

/******** Mapping
*
*/

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="fr.caleasing.bt.model.roles.RoleTiers" table="TIE_ROLE">
<composite-id name="key" class="fr.caleasing.bt.model.roles.RoleKey">
<key-property name="idTiers" column="ID_TIERS" />
<key-many-to-one
name="typeRole"
class="fr.caleasing.bt.model.roles.TypeRole" lazy="false">
<column name="CD_TYP_ROLE"/>
</key-many-to-one>
</composite-id>
<many-to-one
name="motifInterd"
class="fr.caleasing.bt.model.codifobject.MotifInterdRole"
fetch="join"
lazy="false"
not-null="false">
<column name="CD_MOTIF_INTERD"/>
</many-to-one>
......
......
<many-to-one
name="statut"
not-null="true"
class="fr.caleasing.bt.model.codifobject.Statut"
fetch="join"
lazy="false">
<column name="CD_STATUT"/>
</many-to-one>
........
.......

</class>
</hibernate-mapping>


All works successfully. However, if two codifications class (with # type) have identical value of code (Functionaly, It's possible).

(
An Example on Table RoleTiers:

ID_TIERS = XXXXXXX
CD_TYP_ROLE = YYYYYYYYYY
CD_MOTIF_INTERD = 'INAC'(Class MotifInterdRole)
DT_INTERD_ROLE = DD/MM/YYYY
ID_USER_CREAT = XXXXXXXXXXX
DT_CREAT=DD/MM/YYYY
ID_USER_DERN_MAJ = XXXXXXXXXXX
DT_DERN_MAJ=DD/MM/YYYY
CD_STATUT='INAC'(Class Statut)
)


I get this exception:


[01/06/06 13:42:19:996 CEST] 1a53237b WebGroup E SRVE0026E: [Erreur de servlet]-[exception setting property value with CGLIB (set hibernate.cglib.use_reflection_optimizer=false for more info) setter of fr.caleasing.bt.model.roles.RoleTiers.setStatut; nested exception is org.hibernate.PropertyAccessException: exception setting property value with CGLIB (set hibernate.cglib.use_reflection_optimizer=false for more info) setter of fr.caleasing.bt.model.roles.RoleTiers.setStatut]: org.springframework.orm.hibernate3.HibernateSystemException: exception setting property value with CGLIB (set hibernate.cglib.use_reflection_optimizer=false for more info) setter of fr.caleasing.bt.model.roles.RoleTiers.setStatut; nested exception is org.hibernate.PropertyAccessException: exception setting property value with CGLIB (set hibernate.cglib.use_reflection_optimizer=false for more info) setter of fr.caleasing.bt.model.roles.RoleTiers.setStatut
org.hibernate.PropertyAccessException: exception setting property value with CGLIB (set hibernate.cglib.use_reflection_optimizer=false for more info) setter of fr.caleasing.bt.model.roles.RoleTiers.setStatut
at org.hibernate.tuple.PojoEntityTuplizer.setPropertyValuesWithOptimizer(PojoEntityTuplizer.java(Inlined Compiled Code))
at org.hibernate.tuple.PojoEntityTuplizer.setPropertyValues(PojoEntityTuplizer.java(Compiled Code))
at org.hibernate.persister.entity.AbstractEntityPersister.setPropertyValues(AbstractEntityPersister.java(Compiled Code))
at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java(Compiled Code))
at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java(Compiled Code))
at org.hibernate.loader.Loader.doQuery(Loader.java(Compiled Code))
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
at org.hibernate.loader.Loader.doList(Loader.java:2150)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2029)
at org.hibernate.loader.Loader.list(Loader.java:2024)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:369)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:300)
at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:153)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1127)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
at org.springframework.orm.hibernate3.HibernateTemplate$29.doInHibernate(HibernateTemplate.java:807)
at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:356)
at org.springframework.orm.hibernate3.HibernateTemplate.find(HibernateTemplate.java:798)
at org.springframework.orm.hibernate3.HibernateTemplate.find(HibernateTemplate.java:790)
at fr.caleasing.bt.dao.roles.hibernate.RolesDAOHibernate.getListeRoles(RolesDAOHibernate.java:43)
at fr.caleasing.bt.service.roles.impl.RoleServiceImpl.getListeRoles(RoleServiceImpl.java:85)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:79)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java(Compiled Code))
at java.lang.reflect.Method.invoke(Method.java(Compiled Code))
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:292)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:155)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:122)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:144)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:174)
at $Proxy5.getListeRoles(Unknown Source)
at fr.caleasing.bt.web.action.GestionRolesAction.loadRoles(GestionRolesAction.java:825)
at fr.caleasing.bt.web.action.GestionRolesAction.view(GestionRolesAction.java:131)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:79)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java(Compiled Code))
at java.lang.reflect.Method.invoke(Method.java(Compiled Code))
at org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:276)
at fr.caleasing.bt.web.action.BaseAction.execute(BaseAction.java:175)
at org.springframework.web.struts.DelegatingActionProxy.execute(DelegatingActionProxy.java:106)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:421)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:226)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1164)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:397)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at com.ibm.ws.webcontainer.servlet.StrictServletInstance.doService(StrictServletInstance.java:110)
at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet._service(StrictLifecycleServlet.java:174)
at com.ibm.ws.webcontainer.servlet.IdleServletState.service(StrictLifecycleServlet.java:313)
at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet.service(StrictLifecycleServlet.java:116)
at com.ibm.ws.webcontainer.servlet.ServletInstance.service(ServletInstance.java:283)
at com.ibm.ws.webcontainer.servlet.ValidServletReferenceState.dispatch(ValidServletReferenceState.java:42)
at com.ibm.ws.webcontainer.servlet.ServletInstanceReference.dispatch(ServletInstanceReference.java:40)
at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:76)
at com.opensymphony.module.sitemesh.filter.PageFilter.parsePage(PageFilter.java:118)
at com.opensymphony.module.sitemesh.filter.PageFilter.doFilter(PageFilter.java:52)
at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:132)
at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:71)
at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.handleWebAppDispatch(WebAppRequestDispatcher.java:974)
at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.dispatch(WebAppRequestDispatcher.java:564)
at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.forward(WebAppRequestDispatcher.java:200)
at com.ibm.ws.webcontainer.srt.WebAppInvoker.doForward(WebAppInvoker.java:119)
at com.ibm.ws.webcontainer.srt.WebAppInvoker.handleInvocationHook(WebAppInvoker.java:276)
at com.ibm.ws.webcontainer.cache.invocation.CachedInvocation.handleInvocation(CachedInvocation.java:71)
at com.ibm.ws.webcontainer.srp.ServletRequestProcessor.dispatchByURI(ServletRequestProcessor.java:182)
at com.ibm.ws.webcontainer.oselistener.OSEListenerDispatcher.service(OSEListener.java:334)
at com.ibm.ws.webcontainer.http.HttpConnection.handleRequest(HttpConnection.java:56)
at com.ibm.ws.http.HttpConnection.readAndHandleRequest(HttpConnection.java:618)
at com.ibm.ws.http.HttpConnection.run(HttpConnection.java:439)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:672)
Caused by: net.sf.cglib.beans.BulkBeanException: fr.caleasing.bt.model.codifobject.MotifInterdRole
at fr.caleasing.bt.model.roles.RoleTiers$$BulkBeanByCGLIB$$eefe7481.setPropertyValues(<generated>)
... 71 more
Caused by: java.lang.ClassCastException: fr.caleasing.bt.model.codifobject.MotifInterdRole
... 72 more





Thanks in advance for any assistance you can offer.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 02, 2006 2:02 am 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
The first step in solving this problem is to read the exception. Let me quote a little bit of it to you:

set hibernate.cglib.use_reflection_optimizer=false for more info

_________________
Code tags are your friend. Know them and use them.


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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.