简体   繁体   English

集合未充满OneToMany关系-EclipseLink

[英]Collection isn't filled with OneToMany relationship - EclipseLink

I'm mapping a database (Oracle 11g) to JPA entities using EclipseLink. 我正在使用EclipseLink将数据库(Oracle 11g)映射到JPA实体。 I have mapped almost every table to JPA objects but I've just found a problem: 我几乎将每个表都映射到JPA对象,但是我刚发现一个问题:

In the \\Curve\\ entity I have the following fields: 在\\ Curve \\实体中,我具有以下字段:

@Id
@Column(name = "COD_CURVE")
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "seq.gen")
@SequenceGenerator(name = "seq.gen.curve", sequenceName = "SEQCURVE", allocationSize = 1)
private long codCurve;

@Id
@Column(name = "FEC_HISTORIC")
@Temporal(javax.persistence.TemporalType.DATE)
private Date fecHistoric;

@OneToMany(mappedBy="codCurve", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
private Collection<CurveDetail> detailsCollection;

In the \\CurveDetail\\ entity I have this: 在\\ CurveDetail \\实体中,我有以下内容:

@ManyToOne
@JoinColumns({
    @JoinColumn(name = "COD_CURVE", referencedColumnName = "COD_CURVE"),
    @JoinColumn(name = "FEC_HISTORIC", referencedColumnName = "FEC_HISTORIC")
})
private Curve codCurve;

The problem is that when I query the \\Curve\\ entity, the details always are null, despite the fact that there is valid data in both tables. 问题是,当我查询\\ Curve \\实体时,尽管两个表中都有有效数据,但细节始终为空。 Checking the database I've noticed that there are no foreign key constraints in the \\CurveDetail\\ table, so I wonder ¿Are these constraints required to map the database correctly? 检查数据库我注意到\\ CurveDetail \\表中没有外键约束,所以我想知道“是否需要这些约束才能正确映射数据库? I haven't tried to add the FK constraint myself because I'm not allowed to (have to ask a DBA to do it, and it'll take a week). 我没有尝试自己添加FK约束,因为不允许这样做(必须请DBA这样做,这需要一周的时间)。

Thanks in advance! 提前致谢!

Having a foreign key is not required. 不需要外键。

Check the SQL that is generated by enabling logging ("eclipselink.logging.level"="finest") 检查通过启用日志记录生成的SQL(“ eclipselink.logging.level” =“ finest”)

Try executing the same SQL with the same database to see if the data exists. 尝试对相同的数据库执行相同的SQL,以查看数据是否存在。

Also ensure you are not corrupting the shared cache by inserting/updating an object with a null collection. 还应通过插入/更新具有null集合的对象来确保不破坏共享缓存。 You must maintain both sides of a bi-directional relationship. 您必须保持双向关系的双方。 You could try disabling the cache to see if this is what you are doing. 您可以尝试禁用缓存,看看这是否在做。

As I know having a FK constraint is not mandatory. 据我所知,FK约束不是强制性的。 Once I had the same problem (but it was Oracle 9i) and found out that the name of Entity class should match the name of the table you want to map, and also JPA SQL and Hibernate HQL are both case sensitive so be careful in writing @Column tag. 一旦遇到相同的问题(但它是Oracle 9i),发现Entity类的名称应与您要映射的表的名称匹配,并且JPA SQL和Hibernate HQL都区分大小写,因此在编写时要小心@Column标签。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM