Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] Specification interpretation question

Hello Laird,

e2.getE1() will return null until e2 gets refreshed from the database (following a flush/commit), or it is set by the application directly. JPA does not provide relationship maintenance, and determining that the relationship changed/exists because a basic mapping changed is an extreme form of relationship maintenance. Doing so would be provider specific, and not is implemented by EclipseLink (though you could set it to occur with events or change listeners).
Best Regards,
Chris

Laird Nelson wrote:
Without checking to see what the behavior is, please tell me what you think the behavior should be for the following scenario:

I have an entity E1 that has a primary key field named x:

@Entity(name = "E1")
public class E1 implements Serializable {
  @Id
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  @Column(name = "x")
  private int x;

  public int getX() {
    return this.x;
  }
}

I have an entity E2 like this:

@Entity(name = "E2")
public class E2 implements Serializable {
  @ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "e1", referencedColumnName = "x", insertable = false, updatable = false)
  private E1 e1;

  @Column(name = "e1")
  private int e1ID;

  public E2() {
    super();
  }

  public int getE1ID() {
    return this.e1ID;
  }

  public void setE1ID(final int code) {
    this.e1ID = code;
  }

  public E1 getE1() {
    return this.e1;
  }

}

In a container-managed stateless EJB, suppose someone has passed in an E2 whose e1ID field has been set explicitly to a valid e1.x value, as though constructed thusly:

final E2 e2 = new E2();
e2.setE1ID(5); // assuming that in the data store there is an E1 with a primary key of 5

Now, what should be the behavior in this EJB if I do this:

assert e2.getE1ID(5); // i.e. verify the conditions described above
e2 = this.entityManager.merge(e2);
assert e2 != null;
*final E1 e1 = e2.getE1(); // XXX what should be the result here? Should e1 be null or not?*

I've asked the same problem of the OpenJPA folks and I am curious to hear the EclipseLink team's answer.

Thanks,
Laird
------------------------------------------------------------------------

_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users


Back to the top