-->
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.  [ 1 post ] 
Author Message
 Post subject: how to use proxy
PostPosted: Fri Apr 29, 2005 3:16 pm 
Newbie

Joined: Fri Apr 29, 2005 2:34 pm
Posts: 4
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.