1

在hibernate中,当使用xml映射多对多时,它使用的是这样的多对多:

<class name="com.lavin.test.app.dao.hibernate.association.many2many.model.Category2" table="category2" catalog="tt">
    <set name="stocks" table="stock_category" inverse="true" lazy="true" fetch="select">
        <key>
            <column name="CATEGORY_ID" not-null="true" />
        </key>
        <many-to-many entity-name="com.lavin.test.app.dao.hibernate.association.many2many.model.Stock2">
            <column name="STOCK_ID" not-null="true" />
        </many-to-many>
    </set>
</class>

但是,当使用注解时,它会像这样使用@ManyToOne:

@Embeddable
public class StockCategoryId3 implements java.io.Serializable {

private Stock3 stock;

private Category3 category;

@ManyToOne
public Stock3 getStock() {
return stock;
}

public void setStock(Stock3 stock) {
this.stock = stock;
}

@ManyToOne
public Category3 getCategory() {
return category;
}

public void setCategory(Category3 category) {
this.category = category;
}
}

映射多对多关系时使用xml和注解不应该一样吗?为什么这两个不同?

4

0 回答 0