1 Reply Latest reply on Aug 11, 2005 4:56 AM by Emmanuel Bernard

    OneToOne Relationship with 2 fields of the same class

    Enzo Poeta Newbie

      Greetings to all

      I need make something live this


      <entity OrdemServico>

      @Table(name = "rkos20")
      public class OrdemServico
      {
      
       // atributos
      
       private String tipoRepasse;
       private long codigoOS;
       private OrdemServico oSOriginal;
       private OrdemServico oSPai;
       private Servico servico;
       private Usuario requisitante;
       private Usuario solicitante;
       private String prioridade;
       private Date dataAbertura;
       private Date dataFechamento;
       private String descProblema;
       private boolean estaAtrasado;
       private Usuario responsavel;
       private String status;
       private boolean fechamentoAutmat;
       private CentroCusto cCustoEmissor;
       private Area areaReceptora;
       private String descAtendimento;
       private Collection<Tarefa> tarefas;
       private int horasTrab;
      
      
      
      @Id(generate = GeneratorType.SEQUENCE , generator="COD_OS_GEN")
      @Column(updatable = true, name = "num_os", nullable = false)
       public long getNumero()
       {
       return codigoOS;
       }
      
      


      <still in OrdemServico>


      
      @OneToOne(cascade = CascadeType.PERSIST)
      @JoinColumn(name="num_os_pai")
       public OrdemServico getOrdemServicoPai()
       {
       return oSPai;
       }
      
      @OneToOne(cascade = CascadeType.PERSIST)
      @JoinColumn(name="num_os_orig")
       public OrdemServico getOrdemServicoOriginal()
       {
       return oSOriginal;
       }
      
      


      the fields "num_os_pai" and "num_os_orig" are reffering other ids of OrdemServico.
      When i try to load an OrdemServico i got the following :

      
      SQL Error: 0, SQLState: 42703
      09:38:38,179 ERROR [JDBCExceptionReporter] ERROR: column ordemservi0_.num_os_pai does not exist
      09:38:38,180 INFO [DefaultLoadEventListener] Error performing load command
      org.hibernate.exception.SQLGrammarException: could not load an entity: [ordemservico.beans.entity.OrdemServico#216]
       at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:59)
       at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
       at org.hibernate.loader.Loader.loadEntity(Loader.java:1709)
       at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:46)
       at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:40)
       at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:2578)
       at org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:358)
       at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:339)
       at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:116)
       at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:170)
       at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:82)
       at org.hibernate.impl.SessionImpl.get(SessionImpl.java:636)
       at org.hibernate.impl.SessionImpl.get(SessionImpl.java:629)
       at org.hibernate.ejb.AbstractEntityManagerImpl.find(AbstractEntityManagerImpl.java:98)
       at org.jboss.ejb3.entity.InjectedEntityManager.find(InjectedEntityManager.java:92)
       at ordemservico.beans.stateless.OrdemServicoDAOBean.find(OrdemServicoDAOBean.java:122)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:585)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:99)
       at org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:32)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:88)
       at org.jboss.aspects.tx.TxPolicy.invokeInCallerTx(TxPolicy.java:113)
       at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:138)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:88)
       at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:61)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:88)
       at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:39)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:88)
       at org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:63)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:88)
       at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:91)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:88)
       at org.jboss.ejb3.stateless.StatelessContainer.localInvoke(StatelessContainer.java:152)
       at org.jboss.ejb3.stateless.StatelessLocalProxy.invoke(StatelessLocalProxy.java:60)
       at $Proxy93.find(Unknown Source)
       at ordemservico.beans.stateful.OrdemServicoManagerBean.localizarOS(OrdemServicoManagerBean.java:241)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:585)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:99)
       at org.jboss.ejb3.entity.ExtendedPersistenceContextPropagationInterceptor.invoke(ExtendedPersistenceContextPropagationInterceptor.java:44)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:88)
       at org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:32)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:88)
       at org.jboss.ejb3.stateful.StatefulInstanceInterceptor.invoke(StatefulInstanceInterceptor.java:133)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:88)
       at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:66)
       at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:134)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:88)
       at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:61)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:88)
       at org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:63)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:88)
       at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:91)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:88)
       at org.jboss.ejb3.stateful.StatefulContainer.dynamicInvoke(StatefulContainer.java:197)
       at org.jboss.aop.Dispatcher.invoke(Dispatcher.java:107)
       at org.jboss.aspects.remoting.AOPRemotingInvocationHandler.invoke(AOPRemotingInvocationHandler.java:69)
       at org.jboss.remoting.ServerInvoker.invoke(ServerInvoker.java:325)
       at org.jboss.remoting.ServerInvoker.invoke(ServerInvoker.java:201)
       at org.jboss.remoting.transport.socket.ServerThread.processInvocation(ServerThread.java:259)
       at org.jboss.remoting.transport.socket.ServerThread.dorun(ServerThread.java:327)
       at org.jboss.remoting.transport.socket.ServerThread.run(ServerThread.java:147)
      Caused by: java.sql.SQLException: ERROR: column ordemservi0_.num_os_pai does not exist
       at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:1471)
       at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1256)
       at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:175)
       at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:389)
       at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:330)
       at org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:240)
       at org.jboss.resource.adapter.jdbc.WrappedPreparedStatement.executeQuery(WrappedPreparedStatement.java:296)
       at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:121)
       at org.hibernate.loader.Loader.getResultSet(Loader.java:1618)
       at org.hibernate.loader.Loader.doQuery(Loader.java:639)
       at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:221)
       at org.hibernate.loader.Loader.loadEntity(Loader.java:1695)
       ... 63 more
      
      
      


      here is my table structure :

      cd_area_exec | integer |
       cd_ser | integer |
       dt_aber_os | timestamp(0) without time zone |
       dc_aten_os | text |
       dc_prob | text |
       dt_enc_os | timestamp(0) without time zone |
       fl_exec_praz | boolean |
       fl_os_fech_autom | boolean |
       ind_desdob_enc | character varying(1) |
       id_usuar_req | character varying(7) |
       id_usuar_sol | character varying(7) |
       id_usuar_exec | character varying(7) |
       num_os | integer | not null
       num_os_orig | integer |
       num_os_pai | integer |
       num_pi | character varying(8) |
       qt_hora_trab | integer |
       st_os | character varying(1) |
       sg_sis | character varying(3) |
       tip_prio | character varying(1) |
       cd_ccust_sol | character varying(5) |
      Índices:
       "rkos10_pkey" PRIMARY KEY, btree (num_os)
      Restrições de chave estrangeira:
       "fkos1001" FOREIGN KEY (cd_area_exec) REFERENCES rkos40(cd_area) ON UPDATE CASCADE
       "fkos1002" FOREIGN KEY (cd_ccust_sol) REFERENCES rkos90(cd_ccust) ON UPDATE CASCADE
       "fkos1003" FOREIGN KEY (cd_ser) REFERENCES rkos20(cd_ser) ON UPDATE CASCADE
       "fkos1004" FOREIGN KEY (id_usuar_req) REFERENCES rkos01(id_usuar) ON UPDATE CASCADE
       "fkos1005" FOREIGN KEY (id_usuar_sol) REFERENCES rkos01(id_usuar) ON UPDATE CASCADE
       "fkos1006" FOREIGN KEY (num_os_orig) REFERENCES rkos10(num_os) ON UPDATE CASCADE ON DELETE SET NULL
       "fkos1007" FOREIGN KEY (num_os_pai) REFERENCES rkos10(num_os) ON UPDATE CASCADE ON DELETE SET NULL
      
      


      I will really aprecciate any help

      Thanks !!!!!