我嘗試設置JPA映射與連接表中的額外列的多對多關係。我的模型看起來是這樣的: Hikelist(ID),項目(ID),ITEMLIST(IDLIST,itItem,數量)問題與JPA多對多連接表中的額外列
我的映射:
項目:
@Entity
@Table(name = "T_ITEM")
public class Item implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.TABLE)
private Long id;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
private Collection<Itemlist> setOfItemHikelist = new ArrayList<Itemlist>();
@OneToMany(fetch = FetchType.LAZY, mappedBy = "pk.item", cascade=CascadeType.ALL)
public Collection<Itemlist> getSetOfItemHikelist() {
return setOfItemHikelist;
}
public void setSetOfItemHikelist(Collection<Itemlist> setOfItemHikelist) {
this.setOfItemHikelist = setOfItemHikelist;
}
}
ITEMLIST:
@Entity
@Table(name = "T_ITEM_LIST")
@AssociationOverrides({
@AssociationOverride(name = "pk.item",
joinColumns = @JoinColumn(name = "iditem")),
@AssociationOverride(name = "pk.hikelist",
joinColumns = @JoinColumn(name = "idlist")) })
public class Itemlist implements Serializable {
private ItemListId pk = new ItemListId();
@EmbeddedId
public ItemListId getPk() {
return pk;
}
public void setPk(ItemListId pk) {
this.pk = pk;
}
@Transient
public Item getItem() {
return getPk().getItem();
}
public void setStock(Item item) {
getPk().setItem(item);
}
@Transient
public Hikelist getHikelist() {
return getPk().getHikelist();
}
public void setCategory(Hikelist hikelist) {
getPk().setHikelist(hikelist);
}
private String quantity;
public String getQuantity() {
return quantity;
}
public void setQuantity(String quantity) {
this.quantity = quantity;
}
}
ItemListId:
@Embeddable
public class ItemListId implements java.io.Serializable{
private Item item;
private Hikelist hikelist;
@ManyToOne
public Item getItem() {
return item;
}
public void setItem(Item item) {
this.item = item;
}
@ManyToOne
public Hikelist getHikelist() {
return hikelist;
}
public void setHikelist(Hikelist hikelist) {
this.hikelist = hikelist;
}
}
我米收到這個錯誤:
引起:org.hibernate.MappingException:無法確定類型 :java.util.Collection中,在表中:T_HIKELIST,對於列: [org.hibernate作爲。 mapping.Column在 org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:310)(setOfItemHikelist)]在 org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:336)在 org.hibernate.mapping .Property.isValid(Property.java:241)at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:496) at org.hibernate.mapping.RootClass.validate(RootClass.java:270)在 org.hibernate.cfg.Configuration.validate(Configuration.java:1358)在 org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1849) 在 org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl $ 4.perform(EntityManagerFactoryBuilderImpl.java:850)
如果有人可以幫助我這個......謝謝!