Im using SequenceGenerator and GeneratedValue with sequence "seq_user_hierarchy" to do a "select nextval('NAME_OF_SEQUENCE')" in the ID field.
Is there any possibility to use a custom query like "select value from NAME_OF_VIEW" instead of the default query?
Is there any other way to insert the result of my custom query in the id field?
Thanks in advance
/**
* 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;
}