我试图强制JPA/Hibernate生成和使用只有小写的表名。我实现了一个命名是这样的:“org.hibernate.DuplicateMappingException”错误是什么意思?
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 phy sical表名[planning]引用了几个逻辑表名:[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;
// ...
}
您能否提供更多信息 - 就像您实体的映射一样。 – Bozho 2011-01-31 15:30:08
我已更新我的问题。让我知道你是否需要更多。谢谢! – Bogdan 2011-01-31 15:42:59