You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-user@db.apache.org by Fernando Bernardino <fe...@ptcom.com.br> on 2004/09/17 20:34:50 UTC
1:1 mapping using super class
Hi everebody!
I have a Super Class named "PessoaVO" and a Sub Class named "PessoaFisicaVO".
So, I set all the atributtes for PessoaVO and for PessoaFisicaVO in a instance of PessoaFisicaVO.
When I try to insert:
15:22:10,858 INFO [STDOUT] [org.apache.ojb.broker.accesslayer.JdbcAccessImpl] ERROR:
15:22:10,858 INFO [STDOUT] SQLException during the execution of the insert (for a br.com.ptcom.webField.model.PessoaFisicaVO): ORA-01400: cannot insert NULL into ("LAB"."PESSOA_FISICA"."CD_CGC_CPF")
15:22:10,858 INFO [STDOUT] ORA-01400: cannot insert NULL into ("LAB"."PESSOA_FISICA"."CD_CGC_CPF")
15:22:10,858 ERROR [STDERR] java.sql.SQLException: ORA-01400: cannot insert NULL into ("LAB"."PESSOA_FISICA"."CD_CGC_CPF")
Once I did this using an object and works really fine.But I want to do this way, using extends.
Thanks for your time, really thanks.
public class PessoaVO implements java.io.Serializable {
private Integer cdCaixaPostal;
private Integer cdCep;
private Integer cdCgcCpf;
private Integer cdDdd;
private Integer cdEstado;
private Integer cdMunicipio;
private Integer cdPais;
private String dscComplemento;
private String dsEndereco;
private String dtAtualizacao;
private String dtValCgc;
private String nmBairro;
private String nmPessoa;
private String nmUsuario;
private Integer nrFax;
private Integer nrFone;
private String tpPessoa;
private PaisVO paisVO;
private MunicipioVO municipioVO;
private EstadoVO estadoVO;
}
public class PessoaFisicaVO extends PessoaVO implements java.io.Serializable {
private Integer cdCgcCpf;
private String dtAtualizacao;
private String dtEmissaoRg;
private String dtNacimento;
private String dtValidadeCarteiraMotorista;
private String ieSexo;
private String nmUsuario;
private String nrCarteiraMotorista;
private String nrCarteiraTrabalho;
private String nrRg;
private String nrTituloEleitor;
private String orgEmissorRg;
private String tpPessoa;
}
<class-descriptor class="br.com.ptcom.webField.model.PessoaVO" table="LAB.PESSOA" >
<field-descriptor
name="cdCgcCpf"
column="CD_CGC_CPF"
jdbc-type="INTEGER"
primarykey="true"
/>
<field-descriptor
name="tpPessoa"
column="TP_PESSOA"
jdbc-type="VARCHAR"
primarykey="true"
/>
<field-descriptor
name="cdPais"
column="CD_PAIS"
jdbc-type="INTEGER"
/>
<reference-descriptor
name="paisVO"
class-ref="br.com.ptcom.webField.model.PaisVO"
auto-retrieve="true"
>
<foreignkey field-ref="cdPais"/>
</reference-descriptor>
<field-descriptor
name="cdEstado"
column="CD_ESTADO"
jdbc-type="INTEGER"
/>
<reference-descriptor
name="estadoVO"
class-ref="br.com.ptcom.webField.model.EstadoVO"
auto-retrieve="true"
>
<foreignkey field-ref="cdEstado"/>
<foreignkey field-ref="cdPais"/>
</reference-descriptor>
<field-descriptor
name="cdMunicipio"
column="CD_MUNICIPIO"
jdbc-type="INTEGER"
/>
<reference-descriptor
name="municipioVO"
class-ref="br.com.ptcom.webField.model.MunicipioVO"
auto-retrieve="true"
>
<foreignkey field-ref="cdMunicipio"/>
<foreignkey field-ref="cdEstado"/>
<foreignkey field-ref="cdPais"/>
</reference-descriptor>
<field-descriptor
name="dtAtualizacao"
column="DT_ATUALIZACAO"
jdbc-type="VARCHAR"
/>
<field-descriptor
name="nmUsuario"
column="NM_USUARIO"
jdbc-type="VARCHAR"
/>
</class-descriptor>
<class-descriptor class="br.com.ptcom.webField.model.PessoaFisicaVO" table="LAB.PESSOA_FISICA" >
<field-descriptor
name="cdCgcCpf"
column="CD_CGC_CPF"
jdbc-type="INTEGER"
primarykey="true"
/>
<reference-descriptor
name="super"
class-ref="br.com.ptcom.webField.model.PessoaVO"
auto-retrieve="true"
auto-insert="true"
>
<foreignkey field-ref="cdCgcCpf"/>
<foreignkey field-ref="tpPessoa"/>
</reference-descriptor>
<field-descriptor
name="tpPessoa"
column="TP_PESSOA"
jdbc-type="VARCHAR"
primarykey="true"
/>
<field-descriptor
name="dtAtualizacao"
column="DT_ATUALIZACAO"
jdbc-type="VARCHAR"
/>
<field-descriptor
name="nmUsuario"
column="NM_USUARIO"
jdbc-type="VARCHAR"
/>
</class-descriptor>
// I set all the atributtes for PessoaVO and PessoaFisicaVO
public void testInsertPessoaFisica() {
try{
PessoaFisicaVO pessoaFisicaVO = new PessoaFisicaVO();
pessoaFisicaVO.setCdCgcCpf(new Integer(18001));
pessoaFisicaVO.setTpPessoa("f");
pessoaFisicaVO.setDsEndereco("rua francisco ribas");
pessoaFisicaVO.setNmPessoa("Bernardino");
pessoaFisicaVO.setNmBairro("Centro");
pessoaFisicaVO.setDscComplemento("apt 21");
pessoaFisicaVO.setCdCep(new Integer(84010260));
pessoaFisicaVO.setCdDdd(new Integer(42));
pessoaFisicaVO.setNrFone(new Integer(2241481));
pessoaFisicaVO.setNrFax(new Integer(12132));
pessoaFisicaVO.setCdCaixaPostal(new Integer(001212));
pessoaFisicaVO.setDtValCgc("30/08/2004");
pessoaFisicaVO.setDtAtualizacao("27/08/2004");
pessoaFisicaVO.setNmUsuario("fernando");
pessoaFisicaVO.setNrRg("037.396.859.05");
pessoaFisicaVO.setOrgEmissorRg("PR");
pessoaFisicaVO.setDtEmissaoRg("12/10/1984");
pessoaFisicaVO.setDtNacimento("19/10/1982");
pessoaFisicaVO.setIeSexo("M");
pessoaFisicaVO.setNrCarteiraTrabalho("13182651");
pessoaFisicaVO.setNrTituloEleitor("42132132");
pessoaFisicaVO.setNrCarteiraMotorista("321321");
pessoaFisicaVO.setDtValidadeCarteiraMotorista("12/06/2006");
PaisVO paisVO = new PaisVO();
paisVO.setCdPais(new Integer(2));
EstadoVO estadoVO = new EstadoVO();
estadoVO.setCdEstado(new Integer(2));
estadoVO.setPaisVO(paisVO);
MunicipioVO municipioVO = new MunicipioVO();
municipioVO.setCdMunicipio(new Integer(3));
municipioVO.setPaisVO(paisVO);
municipioVO.setEstadoVO(estadoVO);
pessoaFisicaVO.setPaisVO(paisVO);
pessoaFisicaVO.setEstadoVO(estadoVO);
pessoaFisicaVO.setMunicipioVO(municipioVO);
PessoaBusinessDelegate pessoaBD = new PessoaBusinessDelegate();
pessoaBD.incluirPessoaFisica(pessoaFisicaVO);
}catch(Exception e){
e.printStackTrace();
}
}
Fernando Bernardino
Re: 1:1 mapping using super class
Posted by Fernando Bernardino <fe...@ptcom.com.br>.
Hi Armin, I'm using OJB 1.0rc5.
I'll use an object to reference the 1:1 mapping, because I can't upgrade my
OJB now... I have no time :(
But thanks for your tip! Really thanks for your time!
> Hi Fernando,
>
> which version of OJB do you use? Till version 1.0.1 the PK value of the
> sub-object was not passed to the super-object. So if you don't use
> auto-increment 'true' the PK of the internal created super object (in
> your case PessoaVO) will not be set.
> Update to 1.0.1 should solve this problem.
>
> regards,
> Armin
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org
Intersection tables and optimistic locking
Posted by "Kollivakkam R. Raghavan" <rk...@cisco.com>.
We have designed all our tables to consistently have a few standard
columns. An optimistic lock col. Called MOD_NUM is one of these cols
(defined as an INT). We do this for intersection tables as well but the
problem is that since we don't have a mapping entry for the table, the
mod_num never gets incremented. Two questions:
1. Is there anyway to automatically have this incremented (without using
triggers - i.e can OJB do it for me)
2. Is this not a good thing to do? The col. Itself is not adding much
value so other than design consistency there is no reason to keep this
col.
Thanks
Raghavan
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org
Re: 1:1 mapping using super class
Posted by Armin Waibel <ar...@apache.org>.
Hi Fernando,
which version of OJB do you use? Till version 1.0.1 the PK value of the
sub-object was not passed to the super-object. So if you don't use
auto-increment 'true' the PK of the internal created super object (in
your case PessoaVO) will not be set.
Update to 1.0.1 should solve this problem.
regards,
Armin
Fernando Bernardino wrote:
> Hi everebody!
> I have a Super Class named "PessoaVO" and a Sub Class named "PessoaFisicaVO".
> So, I set all the atributtes for PessoaVO and for PessoaFisicaVO in a instance of PessoaFisicaVO.
> When I try to insert:
> 15:22:10,858 INFO [STDOUT] [org.apache.ojb.broker.accesslayer.JdbcAccessImpl] ERROR:
> 15:22:10,858 INFO [STDOUT] SQLException during the execution of the insert (for a br.com.ptcom.webField.model.PessoaFisicaVO): ORA-01400: cannot insert NULL into ("LAB"."PESSOA_FISICA"."CD_CGC_CPF")
> 15:22:10,858 INFO [STDOUT] ORA-01400: cannot insert NULL into ("LAB"."PESSOA_FISICA"."CD_CGC_CPF")
> 15:22:10,858 ERROR [STDERR] java.sql.SQLException: ORA-01400: cannot insert NULL into ("LAB"."PESSOA_FISICA"."CD_CGC_CPF")
>
> Once I did this using an object and works really fine.But I want to do this way, using extends.
>
> Thanks for your time, really thanks.
>
> public class PessoaVO implements java.io.Serializable {
>
> private Integer cdCaixaPostal;
> private Integer cdCep;
> private Integer cdCgcCpf;
> private Integer cdDdd;
> private Integer cdEstado;
> private Integer cdMunicipio;
> private Integer cdPais;
> private String dscComplemento;
> private String dsEndereco;
> private String dtAtualizacao;
> private String dtValCgc;
> private String nmBairro;
> private String nmPessoa;
> private String nmUsuario;
> private Integer nrFax;
> private Integer nrFone;
> private String tpPessoa;
>
> private PaisVO paisVO;
> private MunicipioVO municipioVO;
> private EstadoVO estadoVO;
> }
>
> public class PessoaFisicaVO extends PessoaVO implements java.io.Serializable {
>
> private Integer cdCgcCpf;
> private String dtAtualizacao;
> private String dtEmissaoRg;
> private String dtNacimento;
> private String dtValidadeCarteiraMotorista;
> private String ieSexo;
> private String nmUsuario;
> private String nrCarteiraMotorista;
> private String nrCarteiraTrabalho;
> private String nrRg;
> private String nrTituloEleitor;
> private String orgEmissorRg;
> private String tpPessoa;
> }
>
> <class-descriptor class="br.com.ptcom.webField.model.PessoaVO" table="LAB.PESSOA" >
> <field-descriptor
> name="cdCgcCpf"
> column="CD_CGC_CPF"
> jdbc-type="INTEGER"
> primarykey="true"
> />
> <field-descriptor
> name="tpPessoa"
> column="TP_PESSOA"
> jdbc-type="VARCHAR"
> primarykey="true"
> />
> <field-descriptor
> name="cdPais"
> column="CD_PAIS"
> jdbc-type="INTEGER"
> />
> <reference-descriptor
> name="paisVO"
> class-ref="br.com.ptcom.webField.model.PaisVO"
> auto-retrieve="true"
> >
> <foreignkey field-ref="cdPais"/>
> </reference-descriptor>
>
> <field-descriptor
> name="cdEstado"
> column="CD_ESTADO"
> jdbc-type="INTEGER"
> />
> <reference-descriptor
> name="estadoVO"
> class-ref="br.com.ptcom.webField.model.EstadoVO"
> auto-retrieve="true"
> >
> <foreignkey field-ref="cdEstado"/>
> <foreignkey field-ref="cdPais"/>
> </reference-descriptor>
>
> <field-descriptor
> name="cdMunicipio"
> column="CD_MUNICIPIO"
> jdbc-type="INTEGER"
> />
> <reference-descriptor
> name="municipioVO"
> class-ref="br.com.ptcom.webField.model.MunicipioVO"
> auto-retrieve="true"
> >
> <foreignkey field-ref="cdMunicipio"/>
> <foreignkey field-ref="cdEstado"/>
> <foreignkey field-ref="cdPais"/>
> </reference-descriptor>
>
> <field-descriptor
> name="dtAtualizacao"
> column="DT_ATUALIZACAO"
> jdbc-type="VARCHAR"
> />
> <field-descriptor
> name="nmUsuario"
> column="NM_USUARIO"
> jdbc-type="VARCHAR"
> />
> </class-descriptor>
>
> <class-descriptor class="br.com.ptcom.webField.model.PessoaFisicaVO" table="LAB.PESSOA_FISICA" >
> <field-descriptor
> name="cdCgcCpf"
> column="CD_CGC_CPF"
> jdbc-type="INTEGER"
> primarykey="true"
> />
> <reference-descriptor
> name="super"
> class-ref="br.com.ptcom.webField.model.PessoaVO"
> auto-retrieve="true"
> auto-insert="true"
> >
> <foreignkey field-ref="cdCgcCpf"/>
> <foreignkey field-ref="tpPessoa"/>
> </reference-descriptor>
>
> <field-descriptor
> name="tpPessoa"
> column="TP_PESSOA"
> jdbc-type="VARCHAR"
> primarykey="true"
> />
> <field-descriptor
> name="dtAtualizacao"
> column="DT_ATUALIZACAO"
> jdbc-type="VARCHAR"
> />
> <field-descriptor
> name="nmUsuario"
> column="NM_USUARIO"
> jdbc-type="VARCHAR"
> />
> </class-descriptor>
>
> // I set all the atributtes for PessoaVO and PessoaFisicaVO
> public void testInsertPessoaFisica() {
> try{
> PessoaFisicaVO pessoaFisicaVO = new PessoaFisicaVO();
> pessoaFisicaVO.setCdCgcCpf(new Integer(18001));
> pessoaFisicaVO.setTpPessoa("f");
> pessoaFisicaVO.setDsEndereco("rua francisco ribas");
> pessoaFisicaVO.setNmPessoa("Bernardino");
> pessoaFisicaVO.setNmBairro("Centro");
> pessoaFisicaVO.setDscComplemento("apt 21");
> pessoaFisicaVO.setCdCep(new Integer(84010260));
> pessoaFisicaVO.setCdDdd(new Integer(42));
> pessoaFisicaVO.setNrFone(new Integer(2241481));
> pessoaFisicaVO.setNrFax(new Integer(12132));
> pessoaFisicaVO.setCdCaixaPostal(new Integer(001212));
> pessoaFisicaVO.setDtValCgc("30/08/2004");
> pessoaFisicaVO.setDtAtualizacao("27/08/2004");
> pessoaFisicaVO.setNmUsuario("fernando");
> pessoaFisicaVO.setNrRg("037.396.859.05");
> pessoaFisicaVO.setOrgEmissorRg("PR");
> pessoaFisicaVO.setDtEmissaoRg("12/10/1984");
> pessoaFisicaVO.setDtNacimento("19/10/1982");
> pessoaFisicaVO.setIeSexo("M");
> pessoaFisicaVO.setNrCarteiraTrabalho("13182651");
> pessoaFisicaVO.setNrTituloEleitor("42132132");
> pessoaFisicaVO.setNrCarteiraMotorista("321321");
> pessoaFisicaVO.setDtValidadeCarteiraMotorista("12/06/2006");
>
> PaisVO paisVO = new PaisVO();
> paisVO.setCdPais(new Integer(2));
>
> EstadoVO estadoVO = new EstadoVO();
> estadoVO.setCdEstado(new Integer(2));
> estadoVO.setPaisVO(paisVO);
>
> MunicipioVO municipioVO = new MunicipioVO();
> municipioVO.setCdMunicipio(new Integer(3));
> municipioVO.setPaisVO(paisVO);
> municipioVO.setEstadoVO(estadoVO);
>
> pessoaFisicaVO.setPaisVO(paisVO);
> pessoaFisicaVO.setEstadoVO(estadoVO);
> pessoaFisicaVO.setMunicipioVO(municipioVO);
>
> PessoaBusinessDelegate pessoaBD = new PessoaBusinessDelegate();
> pessoaBD.incluirPessoaFisica(pessoaFisicaVO);
> }catch(Exception e){
> e.printStackTrace();
> }
> }
>
>
> Fernando Bernardino
>
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org