[ 
https://issues.apache.org/jira/browse/OPENJPA-2929?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Pawel Veselov updated OPENJPA-2929:
-----------------------------------
    Description: 
Say you have entity A that has a reference to entity B.

Say entity B is identified by a compound key

{code:java}
@Entity
public class A {
  @Id
  private long id;
  @JoinColumns({
      @JoinColumn(name = "b_id1", referencedColumnName = "id1"),
      @JoinColumn(name = "b_id2", referencedColumnName = "id2")
      })
  private B b;
  @Column(
      name = "b_id1",
      insertable = false,
      updatable = false
  )
  private String bId2;
  @Column(
      name = "b_id2",
      insertable = false,
      updatable = false
  )
  private String bId2;
}
@Entity @IdClass(ID2.class)
public class B {
  @Id @Column("id1")
  private String id1;
  @Id @Column("id2")
  private String id2;
}
public class ID2 {
  private String id1;
  private String id2;
  public ID2() {}
  public ID2(String id1, String id2) {
    this.id1 = id1;
    this.id2 = id2;
  }
}
{code}

After calling {{a.setB(b)}}, and calling {{em.persist(a)}}, the values of 
{{a.bId1}} and {{a.bId2}} are either not set, or set to the same value, either 
from {{b.id1}} or from {{b.id2}}.

This is because {{RowImpl.setJoinRefColumn()}} sets values for all A’s columns 
that point to B for every B primary key columns.



  was:
Say you have entity A that has a reference to entity B.

Say entity B is identified by a compound key

{code:java}
@Entity
public class A {
  @Id
  private long id;
  @JoinColumns({
      @JoinColumn(name = "b_id1", referencedColumnName = "id1"),
      @JoinColumn(name = "b_id2", referencedColumnName = "id2")
      })
  private B b;
  @Column(
      name = "b_id1",
      insertable = false,
      updatable = false
  )
  private String bId2;
  @Column(
      name = "b_id2",
      insertable = false,
      updatable = false
  )
  private String bId2;
}
@Entity @IdClass(ID2.class)
public class B {
  @Id @Column("id1")
  private String id1;
  @Id @Column("id2")
  private String id2;
}
public class ID2 {
  private String id1;
  private String id2;
  public ID2() {}
  public ID2(String id1, String id2) {
    this.id1 = id1;
    this.id2 = id2;
  }
}
{code}

After calling {{a.setB(b)}}, and calling {{em.persist(a)}}, the values of 
{{a.bId1}} and {{a.bId2}} are set randomly, either from {{b.id1}} or from 
{{b.id2}}.

This is because {{RowImpl.setJoinRefColumn()}} sets values for all A’s columns 
that point to B for every B primary key columns.




> Filling inverse FK columns is broken for compound keys
> ------------------------------------------------------
>
>                 Key: OPENJPA-2929
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-2929
>             Project: OpenJPA
>          Issue Type: Bug
>          Components: jdbc
>    Affects Versions: 3.1.2, 3.2.2, 4.0.1
>            Reporter: Pawel Veselov
>            Priority: Major
>
> Say you have entity A that has a reference to entity B.
> Say entity B is identified by a compound key
> {code:java}
> @Entity
> public class A {
>   @Id
>   private long id;
>   @JoinColumns({
>       @JoinColumn(name = "b_id1", referencedColumnName = "id1"),
>       @JoinColumn(name = "b_id2", referencedColumnName = "id2")
>       })
>   private B b;
>   @Column(
>       name = "b_id1",
>       insertable = false,
>       updatable = false
>   )
>   private String bId2;
>   @Column(
>       name = "b_id2",
>       insertable = false,
>       updatable = false
>   )
>   private String bId2;
> }
> @Entity @IdClass(ID2.class)
> public class B {
>   @Id @Column("id1")
>   private String id1;
>   @Id @Column("id2")
>   private String id2;
> }
> public class ID2 {
>   private String id1;
>   private String id2;
>   public ID2() {}
>   public ID2(String id1, String id2) {
>     this.id1 = id1;
>     this.id2 = id2;
>   }
> }
> {code}
> After calling {{a.setB(b)}}, and calling {{em.persist(a)}}, the values of 
> {{a.bId1}} and {{a.bId2}} are either not set, or set to the same value, 
> either from {{b.id1}} or from {{b.id2}}.
> This is because {{RowImpl.setJoinRefColumn()}} sets values for all A’s 
> columns that point to B for every B primary key columns.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to