简体   繁体   English

如何在Hibernate中将单个Java模型对象映射到两个相同的视图?

[英]How to map a single java model object to two identical views in Hibernate?

I am trying to map a single java class to two identical views depends on the value of a field in this class: 我试图将单个java类映射到两个相同的视图,具体取决于此类中字段的值:

here is my java class: 这是我的java类:

@Entity
@Immutable
@Table(name = "VIEW_ACCOUNT_PERMISSION")
public class AccountPermission implements Serializable {

@Id
@Column(name = "PERMISSION_ID")
private String id;

@Column(name = "ACCOUNT_ID")
private Long accountId;

@Column(name = "OBJECT_TYPE_ID")
@Type(type = "refObjectType")
private RefObjectType objectType;

// getters and setters
}

right now it mapped to just one view ("VIEW_ACCOUNT_PERMISSION"). 现在,它仅映射到一个视图(“ VIEW_ACCOUNT_PERMISSION”)。 Not to mention the OBJECT_TYPE_ID field can be 1,2 or 3. Now I want to create another view the same as the "VIEW_ACCOUNT_PERMISSION" lets say "VIEW_ACCOUNT_PERMISSION2" which will have the records with OBJECT_TYPE_ID equals to 3 (1 and 2 will stay in the old view). 更不用说OBJECT_TYPE_ID字段可以为1,2或3。现在,我想创建另一个与“ VIEW_ACCOUNT_PERMISSION”相同的视图,比如说“ VIEW_ACCOUNT_PERMISSION2”,其中OBJECT_TYPE_ID等于3的记录(1和2将保留在旧视图)。

I can create another java model and map it to the new view but I don't like that. 我可以创建另一个Java模型并将其映射到新视图,但是我不喜欢这样。 Is there any way to use single java model and then maps it (discriminate probably) to two views based on the value of objectType ? 有什么方法可以使用单个java模型,然后根据objectType的值将其映射(可能区分)到两个视图?

You can search on basis of entity names. 您可以根据实体名称进行搜索。 One Hibernate pojo class can denote to multiple entity names with different tables. 一个Hibernate pojo类可以表示具有不同表的多个实体名称。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM