我正在尝试强制JPA / Hibernate仅生成和使用小写表名。 我已经实现了这样的一种NamingStrategy:
public class MyNamingStrategy extends DefaultNamingStrategy {
@Override
public String classToTableName(String className) {
return super.classToTableName(className).toLowerCase();
}
}
我已经通过在persistence.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)
“Same physical table name [planning] references several logical table names: [Planning], [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;
// ...
}