简体   繁体   中英

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:

here is my java class:

@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"). 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).

I can create another java model and map it to the new view but I don't like that. Is there any way to use single java model and then maps it (discriminate probably) to two views based on the value of objectType ?

You can search on basis of entity names. One Hibernate pojo class can denote to multiple entity names with different tables.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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