gpt4 book ai didi

java - org.hibernate.AnnotationException : Use of @OneToMany or @ManyToMany targeting an unmapped class

转载 作者:行者123 更新时间:2023-12-02 03:07:53 35 4
gpt4 key购买 nike

我正在尝试对产品规范使用 onetomany 映射,我从描述中复制了类似的工作代码。我正在提供我的所有代码。

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;
}

最佳答案

从错误信息可以知道实体没有正确映射。

  • 确保您导入的是 javax.persistence.entity,而不是 org.hibernate.annotations.entity
  • 此外,请确保该实体已在配置文件(persistence.xml、hibernate.cfg.xml)中列出。

关于java - org.hibernate.AnnotationException : Use of @OneToMany or @ManyToMany targeting an unmapped class,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41502113/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com