I have a problem with the use of proxy in hibernate with the following structure of classes:
public interface Orgao {
public void setCodigoOrgao(int codigoOrgao);
public void setNomeOrgao(String nomeOrgao);
public int getCodigoOrgao();
public String getNomeOrgao();
}
public final class OrgaoImpl implements Orgao {
private int codigoOrgao;
private String nomeOrgao;
public final void setCodigoOrgao(int codigoOrgao) {
this.codigoOrgao = codigoOrgao;
}
public final void setNomeOrgao(String nomeOrgao) {
this.nomeOrgao = nomeOrgao;
}
public final int getCodigoOrgao() {
return codigoOrgao;
}
public final String getNomeOrgao() {
return nomeOrgao;
}
}
public class OrgaoProxyDinamico extends AbstractProxy {
private OrgaoImpl orgao;
private OrgaoProxyDinamico(OrgaoImpl orgao) {
super(orgao);
this.orgao = orgao;
}
public static Orgao getInstancia(int codigoOrgao, String nomeOrgao) {
Orgao orgao = null;
OrgaoImpl delegate = null;
delegate = new OrgaoImpl(codigoOrgao, nomeOrgao);
orgao = (Orgao) Proxy.newProxyInstance(delegate.getClass().getClassLoader(), delegate.getClass().getInterfaces(), new OrgaoProxyDinamico(delegate));
return orgao;
}
public Class getDelegateClass() {
return Orgao.class;
}
}
And I've mapped these classes in only one file. Here it is:
<hibernate-mapping>
<class name="Orgao" table="SIGA_ORGAO">
<id name="codigoOrgao" column="CD_ORG" >
<generator class="sequence">
<param name="sequence">SQ_CD_ORG</param>
</generator>
</id>
<property name="nomeOrgao" column="NM_ORG" />
</class>
</hibernate-mapping>
I'm using hibernate3 and when I try to load an object of this class I get this error:
org.hibernate.InstantiationException: Cannot instantiate abstract class or interface: siga.estruturaFisica.orgao.Orgao
at org.hibernate.tuple.PojoInstantiator.instantiate(PojoInstantiator.java:56)
at org.hibernate.tuple.PojoInstantiator.instantiate(PojoInstantiator.java:84)
at org.hibernate.tuple.AbstractTuplizer.instantiate(AbstractTuplizer.java:221)
at org.hibernate.persister.entity.BasicEntityPersister.instantiate(BasicEntityPersister.java:2962)
at org.hibernate.impl.SessionImpl.instantiate(SessionImpl.java:984)
at org.hibernate.impl.SessionImpl.instantiate(SessionImpl.java:976)
at org.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:865)
at org.hibernate.loader.Loader.getRow(Loader.java:787)
at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:293)
at org.hibernate.loader.Loader.doQuery(Loader.java:387)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:206)
at org.hibernate.loader.Loader.doList(Loader.java:1515)
at org.hibernate.loader.Loader.list(Loader.java:1498)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:369)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:266)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:788)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:74)
at org.hibernate.impl.AbstractQueryImpl.uniqueResult(AbstractQueryImpl.java:588)
at siga.estruturaFisica.orgao.RepositorioOrgaosHbm.consultarOrgao(RepositorioOrgaosHbm.java:714)
I've tried to change to
<class name="Orgao" table="SIGA_ORGAO" lazy="false">
but I got an error in proxy initialization.
Does anyone know how can I solve this problem? I don't know if I have to change the mapping file, the structure of the classes or anything else.
Diego Martins
|