Hi all,
I'm having trouble with a query which has join the tables in my system with a view of the legacy system.
I'm having relationship problems of these two classes:
Code:
@SuppressWarnings("serial")
@Entity
@Table(name="VWEC_RELATORES")
public class RelatorDadosVO extends AbstractVO implements IRelatorVO {
@Id
@SequenceGenerator(name = "REL_ID_D", sequenceName = "SQ_RELATOR", allocationSize = 1)
@GeneratedValue(strategy = GenerationType.AUTO, generator = "REL_ID_D")
@Column(name = "ID_RELATOR_SPL" , unique = true, nullable = false)
@OrderBy("DT_SISTEMA DESC" )
private Long id;
@OneToMany(mappedBy = "relator", fetch=FetchType.LAZY)
private List<DocumentoRelatorVO> documentosRelator;
@OneToMany(mappedBy = "relatorDoc", fetch=FetchType.LAZY)
private List<DocumentoRelatorVO> documentosRelatorDoc;
@Column(name = "ID_DOCUMENTO", nullable = false, insertable=false, updatable=false)
private Long idDocumento;
@Column(name = "ID_DOCUMENTO_SPL", nullable = false, insertable=false, updatable=false)
private Long idDocumentoSPL;
@Column(name = "ID_COMISSAO_SPL", nullable = false, insertable=false, updatable=false)
private Long idComissaoSPL;
@Column(name="NM_RELATOR", nullable=true)
private String nMRelator;
@Temporal(TemporalType.TIMESTAMP)
@Column(name="DT_SISTEMA", nullable=true)
private Calendar dtSistema;
@Column(name="FL_ATIVO", nullable=true)
private String ativo;
// gets, setters
}
Code:
@Entity
@Table(name="TBEC_DOCUMENTO_RELATOR")
public class DocumentoRelatorVO extends AbstractVO implements IDocumentoRelatorVO {
@Id
@SequenceGenerator(name="TBEC_DOCUMENTO_RELATOR_ID_GENERATOR", sequenceName="SQ_DOCUMENTO_RELATOR", allocationSize=1)
@GeneratedValue(strategy=GenerationType.AUTO, generator="TBEC_DOCUMENTO_RELATOR_ID_GENERATOR")
@Column(name="ID_DOCUMENTO_RELATOR", unique=true, nullable=false)
@OrderBy("ID_DOCUMENTO_RELATOR DESC" )
private Long id;
@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(name="ID_RELATOR_SPL", updatable=false, insertable=false,nullable=true)
private RelatorVO relator;
@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(name="ID_RELATOR_SPL", updatable=false, insertable=false,nullable=true)
private RelatorDadosVO relatorDados;
@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(name="ID_DOCUMENTO", updatable=false, insertable=false,nullable=true)
private RelatorDadosVO relatorDoc;
//bi-direcional many-to-one associação para DocumentoVO
@ManyToOne(cascade={CascadeType.PERSIST, CascadeType.MERGE}, fetch=FetchType.LAZY)
@JoinColumn(name="ID_DOCUMENTO" ,nullable=true)
private DocumentoVO documentos;
//bi-direcional many-to-one associação para DocumentoVO
@ManyToOne(cascade={CascadeType.PERSIST, CascadeType.MERGE}, fetch=FetchType.LAZY)
@JoinColumns({
@JoinColumn(name = "ID_DOCUMENTO", referencedColumnName = "ID_DOCUMENTO", insertable=false, updatable=false),
@JoinColumn(name = "ID_COMISSAO", referencedColumnName = "ID_COMISSAO", insertable=false, updatable=false)
})
private DocumentoComissaoVO documentosComissao;
// TODO Deve ser usado TIMESTAMP ou DATE?
@Temporal(TemporalType.TIMESTAMP)
@Column(name="DT_DISTRIBUICAO_RELATOR", nullable=true)
private Date dataDistribuicao;
// TODO Deve ser usado TIMESTAMP ou DATE?
@Temporal(TemporalType.TIMESTAMP)
@Column(name="DT_MANIFESTACAO_RELATOR", nullable=true)
private Date dataManifestacao;
//bi-direcional many-to-one associação para TipoManifestacaoVO
@ManyToOne(cascade={CascadeType.PERSIST, CascadeType.MERGE}, fetch=FetchType.EAGER)
@JoinColumn(name="ID_TIPO_MANIFESTACAO")
private TipoManifestacaoVO tiposManifestacoes;
@Column(name="ID_RELATOR_SPL", nullable=false)
private Long idRelatorSPL;
@Column(name="ID_COMISSAO", nullable=false)
private Long idComissao;
@Column(name="FL_ATIVO", nullable=true)
private String ativo;
//unidirecional one-to-many associação para LogDocumentoVO
@OneToMany(cascade={CascadeType.ALL, CascadeType.MERGE},fetch=FetchType.LAZY)
@JoinColumn(name="ID_DOCUMENTO_RELATOR")
private List<LogDocumentoRelatorVO> logsDocumentoRelator;
// gets, setters
}
Nessa query:
Code:
select doc_comissao.ID_DOCUMENTO_COMISSAO,
doc_comissao.FL_ATIVO,
doc_comissao.ID_COMISSAO,
doc_comissao.DT_ENTRADA_COMISSAO,
doc_comissao.DT_SAIDA_COMISSAO,
doc_comissao.TX_DS_SAIDA_COMISSAO,
doc_comissao.ID_DOCUMENTO,
doc.ID_DOCUMENTO,
doc.ID_DOCUMENTO_STATUS,
doc.ID_DOCUMENTO_SPL,
doc.ID_TIPO_DOCUMENTO,
v_docs.ID_DOCUMENTO,
v_docs.TP_PARTICIPANTE,
v_docs.ID_DOCUMENTO_SPL,
v_docs.ID_NATUREZA,
v_docs.ID_PARTICIPANTE,
v_docs.ID_TIPO_DOCUMENTO,
v_docs.NM_NATUREZA,
v_docs.NM_PARTICIPANTE,
v_docs.NR_ANO_LEGISLATIVO,
v_docs.NR_LEGISLATIVO,
doc_status.ID_DOCUMENTO_STATUS,
doc_status.TX_NM_DOCUMENTO_STATUS,
tp_doc.ID_TIPO_DOCUMENTO,
tp_doc.TX_NM_TIPO_DOCUMENTO,
doc_relator.ID_DOCUMENTO,
doc_relator.ID_COMISSAO,
doc_relator.ID_DOCUMENTO_RELATOR,
doc_relator.ID_DOCUMENTO_RELATOR,
doc_relator.FL_ATIVO,
doc_relator.DT_DISTRIBUICAO_RELATOR,
doc_relator.DT_MANIFESTACAO_RELATOR,
doc_relator.ID_DOCUMENTO,
doc_relator.ID_COMISSAO,
doc_relator.ID_RELATOR_SPL,
doc_relator.ID_TIPO_MANIFESTACAO,
relatores.ID_RELATOR_SPL,
relatores.FL_ATIVO,
relatores.DT_SISTEMA,
relatores.ID_COMISSAO_SPL,
relatores.ID_DOCUMENTO,
relatores.ID_DOCUMENTO_SPL,
relatores.NM_RELATOR,
tp_manifest.ID_TIPO_MANIFESTACAO,
tp_manifest.TX_NM_TIPO_MANIFESTACAO
from TBEC_DOCUMENTO_COMISSAO doc_comissao,
TBEC_DOCUMENTO doc,
VWEC_DOCUMENTOS v_docs,
TBEC_DOCUMENTO_STATUS doc_status,
TBEC_TIPO_DOCUMENTO tp_doc,
TBEC_DOCUMENTO_RELATOR doc_relator,
VWEC_RELATORES relatores,
TBEC_TIPO_MANIFESTACAO tp_manifest
where doc_comissao.ID_DOCUMENTO = doc.ID_DOCUMENTO(+)
and doc.ID_DOCUMENTO = v_docs.ID_DOCUMENTO(+)
and doc.ID_DOCUMENTO_STATUS = doc_status.ID_DOCUMENTO_STATUS(+)
and doc.ID_TIPO_DOCUMENTO = tp_doc.ID_TIPO_DOCUMENTO(+)
and doc_comissao.ID_DOCUMENTO = doc_relator.ID_DOCUMENTO(+)
and doc_comissao.ID_COMISSAO = doc_relator.ID_COMISSAO(+)
--and doc_relator.ID_DOCUMENTO = relatores.ID_DOCUMENTO(+)
and doc_relator.ID_RELATOR_SPL = relatores.ID_RELATOR_SPL(+)
and doc_relator.ID_TIPO_MANIFESTACAO =
tp_manifest.ID_TIPO_MANIFESTACAO(+)
and doc_comissao.ID_COMISSAO = 6
and doc.ID_TIPO_DOCUMENTO = 1
order by v_docs.NR_ANO_LEGISLATIVO asc,
v_docs.NR_LEGISLATIVO asc,
relatores.DT_SISTEMA desc,
doc_relator.ID_DOCUMENTO_RELATOR desc
I can not make the relationship of the commented line. Not with Criteria or HQL with. You can do this using this relationship?
I tried to perform this query with Native Query, but it's time to map the object appears as one of PersistentBag and could not move.
Thank you for your help.