我想要实现的是拥有一个模型(实体),该模型可以使用Hibernate在Java中的单个关联或多个关联上属于多个以上的模型。
例如:拥有一个Phone_details实体,该实体可以属于其他实体,例如Employee,Customer实体等,但在Phone_details实体中没有明确包含Employee_id和Customer_id。
在Ruby On Rails背景中,通常按以下方式实现: 图片实体
class Image < ApplicationRecord
belongs_to :imageable, :polymorphic => true
end
然后,其他实体可以通过可成像
与此实体相关联class User < ApplicationRecord
has_one :avatar, :class_name => "Image", :as => :imageable, :dependent => :destroy
end
class Accommodation < ApplicationRecord
has_many :pictures, :class_name => "Image", :as => :imageable, :dependent => :destroy
end
如何使用Hibernate在Java中实现这一目标。