我使用带有序列“seq_user_hierarchy”的 SequenceGenerator 和 GeneratedValue 在 ID 字段中执行“select nextval('NAME_OF_SEQUENCE')”。
是否有可能使用“从 NAME_OF_VIEW 中选择值”之类的自定义查询而不是默认查询?
有没有其他方法可以在 id 字段中插入我的自定义查询结果?
提前致谢
/**
* User hierarchy JPA entity.
*/
@Entity
@Table(name="USER_HIERARCHY")
@Data
@AllArgsConstructor
@RequiredArgsConstructor
@Builder
@EqualsAndHashCode(of={"id"},callSuper=false)
@ToString(of={"id"})
public class UserHierarchy extends AuditableEntity{
/**
* User hierarchy id.
*
* @param id New value for this User hierarchy's id.
* @return The current value of this User hierarchy's id.
*/
@SequenceGenerator(name="seq_user_hierarchy", sequenceName="seq_user_hierarchy")
@Id
@GeneratedValue(generator="seq_user_hierarchy")
private Long id;
/**
* User hierarchy user.
*
* @param id New value for this User hierarchy's user.
* @return The current value of this User hierarchy's user.
*/
@ManyToOne
@JoinColumn(name = "USER_ID")
User user;
/**
* User hierarchy team.
*
* @param id New value for this User hierarchy's team.
* @return The current value of this User hierarchy's team.
*/
@OneToOne
@JoinColumn(name="TEAM_ID")
SalesTeam team;
/**
* User hierarchy branch.
*
* @param id New value for this User hierarchy's branch.
* @return The current value of this User hierarchy's branch.
*/
@OneToOne
@JoinColumn(name="BRANCH_ID")
SalesBranch branch;
/**
* User hierarchy area.
*
* @param id New value for this User hierarchy's area.
* @return The current value of this User hierarchy's area.
*/
@OneToOne
@JoinColumn(name="AREA_ID")
SalesArea area;
/**
* User hierarchy region.
*
* @param id New value for this User hierarchy's region.
* @return The current value of this User hierarchy's region.
*/
@OneToOne
@JoinColumn(name="REGION_ID")
SalesRegion region;
/**
* User hierarchy is team leader.
*
* @param id New value for this User hierarchy's is team leader.
* @return The current value of this User hierarchy's is team leader.
*/
Boolean isTeamleader;
@Temporal(TemporalType.TIMESTAMP)
private Date startDate;
@Temporal(TemporalType.TIMESTAMP)
private Date endDate;
}