尝试设置列" system_user.id"两个不同的价值观

时间:2015-05-25 07:37:45

标签: java exception jpa openjpa

Caused by: org.apache.openjpa.persistence.InvalidStateException: Attempt to set column "system_user.id" to two different values: (class java.lang.Integer)"6", (class java.lang.Long)"3,651" This can occur when you fail to set both sides of a two-sided relation between objects, or when you map different fields to the same column, but you do not keep the values of these fields in synch.
    at org.apache.openjpa.jdbc.sql.PrimaryRow.setObject(PrimaryRow.java:344) ~[openjpa-2.4.0-nonfinal-1598334.jar:2.4.0-nonfinal-1598334]
    at org.apache.openjpa.jdbc.sql.RowImpl.flushJoinValues(RowImpl.java:294) ~[openjpa-2.4.0-nonfinal-1598334.jar:2.4.0-nonfinal-1598334]
    at org.apache.openjpa.jdbc.sql.RowImpl.flushPrimaryKey(RowImpl.java:186) ~[openjpa-2.4.0-nonfinal-1598334.jar:2.4.0-nonfinal-1598334]
    at org.apache.openjpa.jdbc.sql.RowImpl.setPrimaryKey(RowImpl.java:167) ~[openjpa-2.4.0-nonfinal-1598334.jar:2.4.0-nonfinal-1598334]

public class YoungUser extends DatedModel {
    .
    .
    .
    @JoinColumn(referencedColumnName = "id", name = "system_user_id")
    @OneToOne(cascade = CascadeType.ALL)
    @Column(nullable = false)
    public SystemUser getSystemUser() {
        return systemUser;
    }
    .
    . 
    .
}

它在约束条件下运行良好,但在某些时候它停止了正确的行为。

1 个答案:

答案 0 :(得分:0)

@Id
@Column(name = "id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
protected int id;

之前它已被分配给getter。