-->
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: One-to-one and queries
PostPosted: Wed Sep 22, 2004 5:44 pm 
Beginner
Beginner

Joined: Sun Feb 08, 2004 4:09 pm
Posts: 46
Hibernate version:
2.1.6

Mapping documents:
<hibernate-mapping>
<class
name="br.com.ejconsultoria.business.beans.PessoaBean"
table="PESSOA"
dynamic-update="true"
dynamic-insert="true"
>

<id
name="oid"
column="oid_pessoa"
type="string"
length="32"
>
<generator class="uuid.hex">
</generator>
</id>

<discriminator
column="subclass"
type="string"
length="2"
/>

<property
name="nome"
type="string"
update="true"
insert="true"
access="property"
column="str_nome"
length="40"
/>

<component
name="endereco"
class="br.com.ejconsultoria.business.beans.EnderecoBean"
>
<property
name="bairro"
type="string"
update="true"
insert="true"
access="property"
column="str_endereco_bairro"
length="40"
/>

<property
name="cep"
type="string"
update="true"
insert="true"
access="property"
column="str_endereco_cep"
length="9"
/>

<property
name="cidade"
type="string"
update="true"
insert="true"
access="property"
column="str_endereco_cidade"
length="40"
/>

<property
name="complemento"
type="string"
update="true"
insert="true"
access="property"
column="str_endereco_complemento"
length="15"
/>

<many-to-one
name="estado"
class="br.com.ejconsultoria.business.beans.EstadoBean"
cascade="none"
outer-join="auto"
update="true"
insert="true"
access="property"
column="oid_endereco_estado"
/>

<property
name="logradouro"
type="string"
update="true"
insert="true"
access="property"
column="str_endereco_logradouro"
length="30"
/>

<property
name="numero"
type="integer"
update="true"
insert="true"
access="property"
column="int_endereco_numero"
/>

</component>

<set
name="email"
lazy="false"
inverse="false"
cascade="all-delete-orphan"
sort="unsorted"
>

<key
column="oid_pessoa"
>
</key>

<one-to-many
class="br.com.ejconsultoria.business.beans.EmailBean"
/>
</set>

<set
name="telefone"
lazy="false"
inverse="false"
cascade="all-delete-orphan"
sort="unsorted"
>

<key
column="oid_pessoa"
>
</key>

<one-to-many
class="br.com.ejconsultoria.business.beans.TelefoneBean"
/>
</set>

<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-PessoaBean.xml
containing the additional properties and place it in your merge dir.
-->
<subclass
name="br.com.ejconsultoria.business.beans.PessoaFisicaBean"
dynamic-update="true"
dynamic-insert="true"
discriminator-value="PF"
>
<property
name="CPF"
type="string"
update="true"
insert="true"
access="property"
column="str_cpf"
length="12"
/>

<property
name="dataNascimento"
type="date"
update="true"
insert="true"
access="property"
column="date_nascimento"
/>

<component
name="RG"
class="br.com.ejconsultoria.business.beans.RGBean"
>
<property
name="numero"
type="string"
update="true"
insert="true"
access="property"
column="str_rg_numero"
length="11"
/>

<property
name="orgaoEmissor"
type="string"
update="true"
insert="true"
access="property"
column="str_orgao_emissor"
length="15"
/>

</component>

<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-PessoaFisicaBean.xml
containing the additional properties and place it in your merge dir.
-->

</subclass>
<subclass
name="br.com.ejconsultoria.business.beans.PessoaJuridicaBean"
dynamic-update="true"
dynamic-insert="true"
discriminator-value="PJ"
>
<property
name="cnpj"
type="string"
update="true"
insert="true"
access="property"
column="str_cnpj"
length="18"
/>

<property
name="inscricaoEstadual"
type="string"
update="true"
insert="true"
access="property"
column="str_inscricao_estadual"
length="10"
/>

<property
name="inscricaoMunicipal"
type="string"
update="true"
insert="true"
access="property"
column="str_inscricao_municipal"
length="10"
/>

<property
name="razaoSocial"
type="string"
update="true"
insert="true"
access="property"
column="str_razao_social"
length="80"
/>

<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-PessoaJuridicaBean.xml
containing the additional properties and place it in your merge dir.
-->

</subclass>

</class>

</hibernate-mapping>

<?xml version="1.0"?>

<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"ftp://localhost/hibernate-mapping-2.0.dtd">

<hibernate-mapping>
<class
name="br.com.ejconsultoria.business.beans.PrestadorBean"
table="PRESTADOR"
dynamic-update="true"
dynamic-insert="true"
>

<id
name="oid"
column="oid_prestador"
type="string"
length="32"
>
<generator class="uuid.hex">
</generator>
</id>

<discriminator
column="subclass"
type="string"
length="3"
/>

<set
name="habilitacao"
lazy="false"
inverse="false"
cascade="all-delete-orphan"
sort="unsorted"
>

<key
column="oid_prestador"
>
</key>

<one-to-many
class="br.com.ejconsultoria.business.beans.HabilitacaoBean"
/>
</set>

<set
name="tipoVinculo"
table="VINCULACAO"
lazy="false"
inverse="false"
cascade="none"
sort="unsorted"
>

<key
column="oid_prestador"
>
</key>

<many-to-many
class="br.com.ejconsultoria.business.beans.TipoVinculoBean"
column="oid_tipo_vinculo"
outer-join="auto"
/>

</set>

<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-PrestadorBean.xml
containing the additional properties and place it in your merge dir.
-->
<subclass
name="br.com.ejconsultoria.business.beans.PrestadorPessoaJuridicaBean"
dynamic-update="true"
dynamic-insert="true"
discriminator-value="PJ"
>

<one-to-one
name="pessoaJuridica"
class="br.com.ejconsultoria.business.beans.PessoaJuridicaBean"
cascade="all"
outer-join="auto"
constrained="false"
/>

<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-PrestadorPessoaJuridicaBean.xml
containing the additional properties and place it in your merge dir.
-->

</subclass>
<subclass
name="br.com.ejconsultoria.business.beans.PrestadorPessoaFisicaBean"
dynamic-update="true"
dynamic-insert="true"
discriminator-value="PF"
>

<one-to-one
name="pessoaFisica"
class="br.com.ejconsultoria.business.beans.PessoaFisicaBean"
cascade="all"
outer-join="auto"
constrained="false"
/>

<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-PrestadorPessoaFisicaBean.xml
containing the additional properties and place it in your merge dir.
-->
<subclass
name="br.com.ejconsultoria.business.beans.MembroBean"
dynamic-update="true"
dynamic-insert="true"
discriminator-value="M"
>
<property
name="cracha"
type="string"
update="true"
insert="true"
access="property"
column="str_cracha"
length="10"
/>

<many-to-one
name="cursoPUC"
class="br.com.ejconsultoria.business.beans.CursoPUCBean"
cascade="none"
outer-join="auto"
update="true"
insert="true"
access="property"
column="oid_curso"
not-null="true"
/>

<property
name="previsaoDesligamentoEmpresa"
type="date"
update="true"
insert="true"
access="property"
column="date_previsao_desligamento_empresa"
/>

<property
name="previsaoTerminoCurso"
type="date"
update="true"
insert="true"
access="property"
column="date_previsao_termino_curso"
/>

<set
name="ocupacao"
lazy="false"
inverse="false"
cascade="all-delete-orphan"
sort="unsorted"
>

<key
column="oid_membro"
>
</key>

<one-to-many
class="br.com.ejconsultoria.business.beans.OcupacaoBean"
/>
</set>

<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-MembroBean.xml
containing the additional properties and place it in your merge dir.
-->

</subclass>

</subclass>

</class>

</hibernate-mapping>

Code between sessionFactory.openSession() and session.close():
public List findBy (Class entity, Criterion criterion, Collection order, int pageNumber)
{
try
{
Criteria criteria = currentSession().createCriteria(entity);

criteria.add(criterion);

for (Iterator i = order.iterator(); i.hasNext();)
criteria.addOrder((Order) i.next());

criteria.setCacheable(true);

criteria.setFirstResult(pageNumber * PAGE_SIZE);
criteria.setMaxResults(PAGE_SIZE);

return criteria.list();

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

}

Full stack trace of any exception that occurs:
18:37:45,750 INFO [STDOUT] net.sf.hibernate.QueryException: could not resolve property: pessoaFisica.nome of: br.com.ejconsultoria.business.beans.MembroBean
at net.sf.hibernate.persister.AbstractPropertyMapping.toColumns(AbstractPropertyMapping.java:50)
at net.sf.hibernate.expression.AbstractCriterion.getColumns(AbstractCriterion.java:35)
at net.sf.hibernate.expression.SimpleExpression.toSqlString(SimpleExpression.java:40)
at net.sf.hibernate.loader.CriteriaLoader.<init>(CriteriaLoader.java:64)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:3595)
at net.sf.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:238)
at br.com.ejconsultoria.framework.dataservice.Database.findBy(Database.java:276)
at br.com.ejconsultoria.framework.entitydirectory.Entity.find(Entity.java:201)
at br.com.ejconsultoria.framework.actions.SearchEntityAction.execute(SearchEntityAction.java:101)
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:1158)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:415)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:72)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
at org.jboss.web.tomcat.security.JBossSecurityMgrRealm.invoke(JBossSecurityMgrRealm.java:275)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
at java.lang.Thread.run(Thread.java:534)

Name and version of the database you are using:
MySQL latest version (don't remember)


Hi,

When I execute the findBy method passing Expression.like("pessoaFisica.nome", "test") as the criterion parameter, I get this exception. Shouldn't I be able to search "nome" that's one-to-one with PrestadorPessoaFisica?

Thanks in advance,
Thiago Souza


Top
 Profile  
 
 Post subject: Found a possible solution
PostPosted: Wed Sep 22, 2004 6:14 pm 
Beginner
Beginner

Joined: Sun Feb 08, 2004 4:09 pm
Posts: 46
First of all, sorry for posting in the wrong forum.

I found out that using criteria.createAlias would solve me problem, but then I have 2 questions:

1. Will I be able to do something like create.createAlias("pessoaFisica.endereco", "endereco")?

2. Is there any other way of solving this? Cause since this message receives the criterion already built (this is very handy), I can't get the left side of the expression to check If I need to create an alias...

Thanks in advance,
Thiago Souza


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.