所以我在互联网上搜索了我的问题的答案,但没有找到有帮助的东西,基本上需要在两个类之间有一个 ManyToOne 关系,其中一个有一个EmbeddedId
,我将把代码留在这里以及它给出的错误消息(我正在使用 wildfly 运行服务器)。
public class InventoryPK implements Serializable {
@ManyToMany(cascade = CascadeType.ALL)
@JoinColumn(name = "user_id")
private Item itemId;
@ManyToOne
@JoinColumn(name="CD_EMPRESA")
private Company company;
}
@Entity
@Table(name = "inventario", schema = "mxnextmob")
public class Inventory extends BaseModel {
@EmbeddedId
private InventoryPK id;
@SequenceGenerator(schema = "mxnextmob", name = "inventory_sequence", sequenceName = "inventory_sequence", allocationSize = 1, initialValue = 1)
@GeneratedValue(strategy = GenerationType.AUTO, generator = "inventory_sequence")
private Integer inventory;
@Column
private BigDecimal quantity;
@Column
private BigDecimal weight;
}
public class Company extends BaseModel {
@Id
@SequenceGenerator(schema = "mxnextmob", name = "company_sequence", sequenceName = "company_sequence", allocationSize = 1, initialValue = 1)
@GeneratedValue(strategy = GenerationType.AUTO, generator = "company_sequence")
private Integer code;
@Column
private String name;
@OneToMany(mappedBy = "company")
private List<UserSeller> userSeller;
@OneToMany(mappedBy = "id.company")
private List<Inventory> inventories;
}
错误如下:
service jboss.persistenceunit."mxnext-mobile.war#mxnextmobileDS": org.hibernate.AnnotationException: mappedBy 引用一个未知的目标实体属性:br.com.maxiconsystems.mobile.model.Inventory.company in br.com.maxiconsystems.mobile .model.Company.inventory