求助:JPA复合主键其中一个作为外键,不再新建一个外键列的配置?
CREATE TABLE `orders` (`orderId` varchar(14) NOT NULL,
`address` varchar(50) DEFAULT NULL,
PRIMARY KEY (`orderId`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `orderitem` (
`orderId` varchar(14) NOT NULL,
`orderItemId` varchar(4) NOT NULL,
`num` int(11) DEFAULT NULL
PRIMARY KEY (`orderId`,`orderItemId`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
orderitem双PK,orderId是orders的外键
Caused by: org.hibernate.MappingException: Repeated column in mapping for entity: cn.it.entity.OrderItem column: orderId (should be mapped with insert="false" update="false")
如下配置报column重复的异常,求高人帮助
@Entity
@Table(name="orders")
public class Order implements Serializable
{
private String orderId;
private String address;
private Set<OrderItem> items = new HashSet<OrderItem>();
@Id
@Column(length=14)
public String getOrderId()
{
return orderId;
}
...
@Column(length=50)
public String getAddress()
{
return address;
}
....
@OneToMany(mappedBy="order",cascade={CascadeType.PERSIST,CascadeType.MERGE,CascadeType.REMOVE})
public Set<OrderItem> getOrderItems()
{
return items;
}
}
@Entity
public class OrderItem implements Serializable
{
private OrderItemPK id;
private Order order;
private int num;
@EmbeddedId
public OrderItemPK getId()
{
return id;
}
...
@ManyToOne(cascade={CascadeType.MERGE,CascadeType.REFRESH})
@JoinColumn(name="orderId")
public Order getOrder()
{
return order;
}
...
}
@Embeddable
public class OrderItemPK implements Serializable
{
private String orderId;
private String orderItemId;
....
} --------------------编程问答-------------------- 自己顶,求助
补充:Java , Java EE