“org.hibernate.DuplicateMappingException”错误是什么意思?
2022-09-04 23:30:46
我试图强制JPA / Hibernate生成并使用小写的表名。我已经实现了一个命名策略,如下所示:
public class MyNamingStrategy extends DefaultNamingStrategy {
@Override
public String classToTableName(String className) {
return super.classToTableName(className).toLowerCase();
}
}
我通过在持久性中设置此属性来应用它.xml:
<property name="hibernate.ejb.naming_strategy" value="entities.strategy.MyNamingStrategy"/>
当我这样做时,我得到这个堆栈跟踪:
SEVERE: Exception while invoking class org.glassfish.persistence.jpa.JPADeployer prepare method
org.hibernate.DuplicateMappingException: Same physical table name [planning] references several logical table names: [Planning], [OrderProductMan_Planning]
at org.hibernate.cfg.Configuration$MappingsImpl.addTableBinding(Configuration.java:2629)
at org.hibernate.cfg.annotations.TableBinder.buildAndFillTable(TableBinder.java:254)
at org.hibernate.cfg.annotations.TableBinder.bind(TableBinder.java:177)
什么是
相同的物理表名称 [计划] 引用多个逻辑表名称:[计划]、[OrderProductMan_Planning]
意味 着?
实体从错误,尽可能简化。如果您需要其余的,请告诉我。
@Entity
public class Planning implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Integer id;
private Integer qty;
@ManyToOne
private OrderProductMan orderProduct;
....
}
@Entity
@Table
public class OrderProductMan implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
private Integer opId;
@Basic(optional = false)
private int qty;
@ManyToOne(optional = false)
private ProductMan produse;
@ManyToOne(optional = false)
private OrderMan orders;
@Transient
private int totalScheduled;
@Transient
private int totalProduced;
// ...
}