------------------Product实体------------------------------
public class Product implements Serializable{
private Integer id;
private OrderLine orderline;
public OrderLine getOrderline() {
return orderline;
}
public void setOrderline(OrderLine orderline) {
this.orderline = orderline;
}
public Integer getId() {
return id;
}
public void setId(Integer id){
this.id = id;
}
}
----------------OrderLine实体------------------------------
public class OrderLine implements Serializable{
private Integer id;
private Product product;
public Product getProduct() {
return product;
}
public void setProduct(Product product) {
this.product = product;
}
public Integer getId() {
return id;
}
public void setId(Integer id){
this.id = id;
}
}
-----------------------Product___mapping-----------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
<hibernate-mapping package="cn.com.ecport.domain">
<class name="Product" table="product">
<id name="id" column="id" type="java.lang.Integer">
<generator class="increment" />
</id>
<one-to-one name="orderline"
class="OrderLine"
property-ref="product"
cascade="all"></one-to-one>
</class>
</hibernate-mapping>
-----------------------OrderLine___mapping---------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
<hibernate-mapping package="cn.com.ecport.domain">
<class name="OrderLine" table="orderline">
<id name="id" column="id" type="java.lang.Integer">
<generator class="increment"></generator>
</id>
<many-to-one name="product"
class="Product"
column="product_id"
></many-to-one>
</class>
</hibernate-mapping>
---------------------为什么会有这个异常----------------------------------------------
当我执行List listuser =new ProductDAOImpl().findAll();时报异常---》如下(我的配置哪里写的有问题请指点)
Exception in thread "main" org.hibernate.HibernateException: More than one row with the given identifier was found: 3, for class: cn.com.ecport.domain.OrderLine
at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:69)
at org.hibernate.loader.entity.EntityLoader.loadByUniqueKey(EntityLoader.java:85)
at org.hibernate.persister.entity.AbstractEntityPersister.loadByUniqueKey(AbstractEntityPersister.java:1596)
at org.hibernate.type.EntityType.loadByUniqueKey(EntityType.java:608)
at org.hibernate.type.EntityType.resolve(EntityType.java:382)
at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:116)
at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:842)
at org.hibernate.loader.Loader.doQuery(Loader.java:717)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
at org.hibernate.loader.Loader.doList(Loader.java:2211)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2095)
at org.hibernate.loader.Loader.list(Loader.java:2090)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:388)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:338)
at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:172)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1121)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
at cn.com.ecport.dao.daoimpl.ProductDAOImpl.findAll(ProductDAOImpl.java:35)
at cn.com.ecport.dao.daoimpl.ProductDAOImpl.main(ProductDAOImpl.java:47)