我試圖在產品規範中使用onetomany映射,其中從說明中複製了類似的工作代碼。我提供了我所有的代碼。org.hibernate.AnnotationException:使用@OneToMany或@ManyToMany以未映射的類爲目標
Caused by: javax.persistence.PersistenceException: [PersistenceUnit: sm-unit] Unable to build EntityManagerFactory
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:915)
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:890)
at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:74)
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:257)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:310)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1514)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1452)
... 38 more
Caused by: org.hibernate.AnnotationException: Use of @OneToMany or @ManyToMany targeting an unmapped class: com.salesmanager.core.business.catalog.product.model.Product.specifications[com.salesmanager.core.business.catalog.product.model.specification.ProductSpecification]
at org.hibernate.cfg.annotations.CollectionBinder.bindManyToManySecondPass(CollectionBinder.java:1204)
Product.java有記入這樣的:
@OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.REMOVE, mappedBy = "product")
private Set<ProductSpecification> specifications = new HashSet<ProductSpecification>();
ProductSpecification.java低於代碼..
@Entity
@Table(name = "PRODUCT_SPECIFICATION", schema=SchemaConstant.BEAWLP_JAMBIRA_SCHEMA)
public class ProductSpecification extends SalesManagerEntity<Long, ProductSpecification> {
private static final long serialVersionUID = -7991123525661321865L;
@ManyToOne(targetEntity = Product.class)
@JoinColumn(name = "PRODUCT_ID", nullable = false)
private Product product;
@Id
@Column(name = "SPECIFICATION_ID", unique = true, nullable = false)
@TableGenerator(name = "TABLE_GEN", table = "SM_SEQUENCER", pkColumnName = "SEQ_NAME", valueColumnName = "SEQ_COUNT", pkColumnValue = "SPECIFICATION_SEQ_NEXT_VAL")
@GeneratedValue(strategy = GenerationType.TABLE, generator = "TABLE_GEN")
private Long id;
@Column(name="TITLE", length=100)
private String title;
public ProductSpecification() {
}
public Product getProduct() {
return product;
}
public void setProduct(Product product) {
this.product = product;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
嘗試'@OneToMany(...,targetEntity = ProductSpecification)'在你的註釋 – ZeusNet
感謝ZeusNet。 \t 即使添加targetEntity後,我也會得到同樣的例外 – user3338029
您是否也可以提供YouTube產品類的源代碼? – ZeusNet