-3

I don't know why relationships is not been created in my database. I have 7 relationships in a table wherein 5 relations works fine, but 2(materialServico,unidadeMedida) won't appears in database(looking at CONSTRAINT REFERENCES) and nothing appear on log. Anyone experienced this? I'm using eclipselink 2.5.1 with spring 3.2.1.RELEASE and SqlServer 2012(also tested in postgresql). Normally I use Hibernate as ORM...

@JoinColumns({
    @JoinColumn(name = "COD_EMPRESA", referencedColumnName = "COD_EMPRESA", nullable = true, insertable=false, updatable=false),
    @JoinColumn(name = "COD_FILIAL", referencedColumnName = "COD_FILIAL", nullable = true, insertable=false, updatable=false),
    @JoinColumn(name = "COD_CONTA_CONTABIL", referencedColumnName = "COD_CONTA_CONTABIL", nullable = true, insertable=false, updatable=false),
    @JoinColumn(name = "DATA_CONTA_CONTABIL", referencedColumnName = "DATA_CONTA_CONTABIL", nullable = true, insertable=false, updatable=false)})
@ManyToOne(optional = false)
private Conta conta = new Conta();

@JoinColumns({
    @JoinColumn(name = "COD_EMPRESA", referencedColumnName = "COD_EMPRESA", nullable = true, insertable=false, updatable=false),
    @JoinColumn(name = "COD_FILIAL", referencedColumnName = "COD_FILIAL", nullable = true, insertable=false, updatable=false),
    @JoinColumn(name = "COD_UNIDADE_MEDIDA", referencedColumnName = "COD_UNIDADE_MEDIDA", nullable = true, insertable=false, updatable=false)})
@ManyToOne(optional = false)
private UnidadeMedida unidadeMedida = new UnidadeMedida();

 @JoinColumns({
    @JoinColumn(name = "COD_EMPRESA", referencedColumnName = "COD_EMPRESA", nullable = true, insertable=false, updatable=false),
    @JoinColumn(name = "COD_FILIAL", referencedColumnName = "COD_FILIAL", nullable = true, insertable=false, updatable=false),
    @JoinColumn(name = "COD_NAT_OPERACAO", referencedColumnName = "COD_NAT_OPERACAO", nullable = true, insertable=false, updatable=false)})
@ManyToOne(optional = false)
private NaturezaOperacao naturezaOperacao = new NaturezaOperacao();

@JoinColumns({
    @JoinColumn(name = "COD_EMPRESA", referencedColumnName = "COD_EMPRESA", nullable = true, insertable=false, updatable=false),
    @JoinColumn(name = "COD_FILIAL", referencedColumnName = "COD_FILIAL", nullable = true, insertable=false, updatable=false),
    @JoinColumn(name = "CHAVE_NFE", referencedColumnName = "CHAVE_NFE", nullable = true, insertable=false, updatable=false),
    @JoinColumn(name = "DATA_REF", referencedColumnName = "DATA_REF", nullable = true, insertable=false, updatable=false)})
@ManyToOne(optional = false)
private MestreNotaFiscal mestreNotaFiscal = new MestreNotaFiscal();

@JoinColumns({
    @JoinColumn(name = "COD_EMPRESA", referencedColumnName = "COD_EMPRESA", nullable = true, insertable=false, updatable=false),
    @JoinColumn(name = "COD_FILIAL", referencedColumnName = "COD_FILIAL", nullable = true, insertable=false, updatable=false),
    @JoinColumn(name = "COD_ITEM", referencedColumnName = "COD_ITEM", nullable = true, insertable=false, updatable=false)})
@ManyToOne(optional = true)
private MaterialServico materialServico;

Sql logs: It creates the FK for mestreNotaFiscal, filial, conta, naturezaOperacao, empresa. Don't show more FK from this table in the log.

ALTER TABLE SYS033_ITENS_NFS ADD CONSTRAINT SYS033ITENSNFSDATA_REF FOREIGN KEY (DATA_REF, CHAVE_NFE, COD_FILIAL, COD_EMPRESA) REFERENCES SYS032_MESTRE_NFS (DATA_REF, CHAVE_NFE, COD_FILIAL, COD_EMPRESA)
ALTER TABLE SYS033_ITENS_NFS ADD CONSTRAINT SYS033ITENSNFSCDFILIAL FOREIGN KEY (COD_FILIAL, COD_EMPRESA) REFERENCES SYS001_FILIAIS (COD_FILIAL, COD_EMPRESA)
ALTER TABLE SYS033_ITENS_NFS ADD CONSTRAINT SYS033TNSNFSCDCNTCNTBL FOREIGN KEY (COD_CONTA_CONTABIL, COD_FILIAL, DATA_CONTA_CONTABIL, COD_EMPRESA) REFERENCES SYS005_ (COD_CONTA_CONTABIL, COD_FILIAL, DATA_CONTA_CONTABIL, COD_EMPRESA)
ALTER TABLE SYS033_ITENS_NFS ADD CONSTRAINT SYS033TNSNFSCDNTPRACAO FOREIGN KEY (COD_NAT_OPERACAO, COD_FILIAL, COD_EMPRESA) REFERENCES SYS031_NATUREZA_OPERACOES (COD_NAT_OPERACAO, COD_FILIAL, COD_EMPRESA)
ALTER TABLE SYS033_ITENS_NFS ADD CONSTRAINT SYS033ITENSNFSCDMPRESA FOREIGN KEY (COD_EMPRESA) REFERENCES SYS000_EMPRESA (COD_EMPRESA)
  • why is being negated ???? – Thomas D. K. Teixeira Jan 05 '15 at 18:39
  • You gave no information other then many very complex mappings. What exactly are you expecting to happen, and what exactly is happening instead? You might also simplify your model and remove some of the relationships to see which is actually related to the problem - create a simple test case usually helps people figure out what might be going wrong. – Chris Jan 06 '15 at 15:01
  • What exactly are you expecting to happen? Create FK for table materialServico and table unidadeMedida. what exactly is happening instead? Is creating the field for FK, but not creating the FK CONSTRAINT(references) for this 2 tables. I will try to change to hibernate and see if it's a eclipselink problem. – Thomas D. K. Teixeira Jan 08 '15 at 11:56
  • can you show the SQL being issued? See https://wiki.eclipse.org/EclipseLink/Examples/JPA/Logging to turn on logging, as it could be that the constraint is being issued, but a problem occurs which is just ignored. – Chris Jan 08 '15 at 16:43
  • Don't show any issue in log. This table is created without the FOREIGN KEY for materialServico and unidadeMedida. It's like is not there... – Thomas D. K. Teixeira Jan 13 '15 at 13:19
  • Can you show the SQL being used to create a table that has the foreign key vs one that doesn't? – Chris Jan 13 '15 at 14:05
  • I added the logs of FK constraints. The FK missing should be down the displayed logs – Thomas D. K. Teixeira Jan 14 '15 at 15:29
  • Well, show the entities themselves. Is inheritance involved? What are the primary keys of the referenced classes? – Chris Jan 14 '15 at 20:21

1 Answers1

-1

I changed the implementation from eclipselink to hibernate(4.2.1.Final) and it worked! I don't know why have this problem and don't know how to use eclipselink in this situation.