将实体类放入当前模块内,或者使用数据库视图实现跨模块实体的引用。
示例:
假设我们有两个模块:OrderModule 和 ProductModule,其中 ProductModule 定义了一个 Product 实体类,现在想要在 OrderModule 中使用 Product 实体类。
一种解决方法是将 Product 实体类移动到 OrderModule 中,让其在本模块内进行使用:
// OrderModule @Entity @Table(name = "order") public class Order { // ... @ManyToOne @JoinColumn(name = "product_id") private Product product; // ... }
// ProductModule // Product 实体类被删除
另一种解决方法是使用数据库视图,在 OrderModule 中创建一个基于 Product 数据表的视图,并将其作为实体类使用:
// OrderModule @Entity @Table(name = "order_detail_view") public class OrderDetail { // ... @ManyToOne @JoinColumn(name = "product_id") private Product product; // ... }
// ProductModule // Product 实体类不变
// 创建视图 CREATE VIEW order_detail_view AS SELECT o.*, p.name AS product_name FROM order o JOIN product p ON o.product_id = p.id;
上一篇:BaseElements插件在本地工作,但在服务器上无法工作。
下一篇:BaseExpandableListAdapter的getChildrenCount()方法出现了NullPointerException。