当我为第一个实体(customer1)创建数据时,数据已成功创建,但是当我想为第二个实体创建数据时,出现以下错误。我们在两个具有不同表注释名称的不同包中生成这两个实体,所以我不明白为什么我会收到此错误。我们还为每个实体创建不同的持久性单元名称......这个错误的原因可能是什么?
错误在提交中
entityManager.getTransaction().commit();
entityManager.close();
异常 [EclipseLink-4002] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.DatabaseException 内部异常: java.sql.SQLIntegrityConstraintViolationException: 该语句被中止,因为它会导致重复键在“customer02”上定义的“SQL130407132754180”标识的唯一或主键约束或唯一索引中的值。错误代码:20000 调用:INSERT INTO customer02(CUSTOMER, NOTE, BUYERID) VALUES (?, ?, ?) bind => [3 个参数绑定] 查询:InsertObjectQuery(prod2.customer02@7fe4bdcc)
实体 1 客户在包中 ... customer01
package prod1;
import java.util.List;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name="customer01")
public class Customer
{
@Id
@Column(name="customer_number")
private String customer;
private String Note;
private String BuyerId;
实体 2 客户在包中 ... customer02
package prod2;
import java.util.List;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name="customer02")
public class Customer
{
@Id
@Column(name="customer_number")
private String customer;
private String Note;
private String BuyerId;
持久性单位是
-<persistence-unit name="prod1">
<class>prod1.customer01</class>-
<properties><property name="eclipselink.ddl-generation"
value="drop-and-create-tables"/>
<property name="eclipselink.logging.level" value="SEVERE"/>
</properties></persistence-unit>-
-<persistence-unit name="prod2">
<class>prod2.customer02</class>-
<properties><property name="eclipselink.ddl-generation"
value="drop-and-create-tables"/>
<property name="eclipselink.logging.level" value="SEVERE"/>
</properties></persistence-unit>-