Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] ManyToOne issue

It turns out this issue was related to a missed merge. When "user" was properly merged, the issue went away.

Brad Milne wrote:
Could this be the same problem I'm experiencing in my question thread? http://dev.eclipse.org/mhonarc/lists/eclipselink-users/msg06019.html
I've made a sample project available for download which shows the problem.

Cheers
Brad


On 5/04/11 1:59 AM, Tom Ware wrote:
Hi Christian,

Where does "change" come from. Is it a new object? Is it read from the database? What is its @Id? Is it set?

BTW: The spec requires you to set both sides of the relationship. e.g. both change.setChangedBy(user) and user.addChange(change)

-Tom

Christian (VuuRWerK) Seifert wrote:
Hi,

since 4 month i was able to work with eclipselink w/o any problems,
nice work so far! ;)

But now i got a problem where i need your help :/

I have the following relationship:
[=========>8=========]
class Changes {
  @ManyToOne
  @JoinColumn(name = "FK_CHANGED_BY")
  private User changedBy;
}

class User {
  @OneToMany(mappedBy = "changedBy", fetch = FetchType.EAGER)
  private List<Changes> changes = new ArrayList<Changes>();
}

// first try:
change.setChangedBy(user);
em.persist(change);

// another try:
user.addChange(change);  // does also: change.addUser(this);
em.persist(change);
[=========8<=========]

Regardless of which way i try to set the User to the Changes object or
add the Changes to the User object I always got a "ORA-00001: Unique
Constraint (...) violation". It seems eclipselink tries to insert a
new entry in the users table while updating/saving. How can i get rid
of them and instead just set the FK_CHANGED_BY field with the id of
the user (which always already exists!)?

Thanks in advance!

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


Back to the top