Java给实体类副属性_如何处理不同实体类别的不同实体属性

如果我正确地阅读你的情况,听起来你可以通过避免对Thing的继承而更好地服务,而是将类别特定属性作为事物和类别之间关系的属性 .

这样的架构怎么样:

class Category {

protected $id;

protected $title;

protected $things; //@ManyToOne(targetEntity="ThingCategory")

}

class Thing {

protected $id;

protected $title;

protected $description;

protected $category; //@ManyToOne(targetEntity="ThingCategory")

}

/**

* Use [Single|Class]-Table Inheritence to model subject-category attributes.

*

* ThingCategory is just a base class. Modules provide concrete subclasses

* that encapsulate category-specific attributes.

*/

class ThingCategory {

protected $id; //surrogate key, not strictly necessary

protected $thing; //@ManyToOne(targetEntity="Thing")

protected $category //@ManyToOne(targetEntity="Category")

}

class ThingMovieCategory extends ThingCategory{

protected $airingStartDate;

protected $airingEndDate;

}

class ThingCarCategory extends ThingCategory {

protected $horespower;

protected $numberOfDoors;

protected $color;

}

所以,现在事物可以通过替换与之关联的ThingCategory实体在类别之间移动 . 事物的身份永远不会改变,只是它与类别的关系 . 包含在该类别中所需的属性是ThingCategory关系实体的属性,而不是Thing本身的属性 .

编辑:您可能遇到的问题是,在子类化实体时没有记录的修改鉴别器映射的方法 . 不幸的副作用是你的基础模块必须知道每个可能的模块 . 但这可能不是一个大问题 . 如果是,我相信可以通过让每个模块操纵基本实体的ClassMetaData来避免这种情况,但我从来没有打扰过实际的工作 .

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值