Hi Marc -

I wonder what kind of database schema that produces. Normally you would have OneToMany on one side and ManyToOne on the other side, with the mappedBy on the OneToMany side. This is the classical way the foreign keys work in relational database models. I think you do not need ElementJoinColumn as the defaults will be right (but I'm not sure without trying it).

So it would look like this -

public class Retoure {

@OneToMany(mappedBy="retoure", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
   List<RetourePosition> retourePositionList;

}

public class RetourePosition {

   @ManyToOne(cascade = CascadeType.REFRESH, fetch = FetchType.EAGER)
   Retoure retoure;

}


On 4/7/2009 5:14 PM, Marc Logemann wrote:
Hi,

i am getting this and because i have some severe performance problems with our OpenJPA based app, i wanted to ask for help:

[INFO 02:06:25] Log4JLogFactory$LogAdapter.info(80) | Inefficient mapping: You have declared that field "de.logentis.bwh.model.RetourePosition.retoure" is mapped by collection "de.logentis.bwh.model.Retoure.retourePositionList". The mapping would be much more efficient if instead you map "de.logentis.bwh.model.RetourePosition.retoure" and declare that "de.logentis.bwh.model.Retoure.retourePositionList" is mapped by it.

My domain model:

@Entity
@Table(name = "retoure")
@VersionColumn(name = "_version")
public class Retoure {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "oid")
    long oid;

    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@ElementJoinColumn(name = "retoure_oid", referencedColumnName = "oid")
    List<RetourePosition> retourePositionList;

---

@Entity
@VersionColumn(name = "_version")
@Table(name = "retourepos")
public class RetourePosition {

    @Id
    @Column(name = "oid")
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    long oid;

@OneToOne(mappedBy = "retourePositionList", cascade = CascadeType.REFRESH, fetch = FetchType.EAGER)
    Retoure retoure;

---

Table Info: "retoure_oid" is a foreign key field in the "retourepos" table that points to the "oid" field of the "retoure" table.

To me this looks like a good way but the warning says something else. I tried to change the mapping so that the actual mapping will be done in "retoure" atrtribute and just do a "mappedBy" reference on "retourePositionList" but then it wont work at all. When i read the warning, i would exactly expect that this would work. So what am i doing wrong here?

---
regards
Marc Logemann
http://www.logemann.org
http://www.logentis.de







Reply via email to