0

我使用带有序列“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;

}
4

1 回答 1

0

请尝试以下代码更改并确认它是否有效。

public class UserHierarchy extends AuditableEntity {

...

@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "author_generator")
@SequenceGenerator(name="author_generator", sequenceName = "author_seq")
@Column(name = "id", updatable = false, nullable = false)
private Long id;

...

}

对上述代码片段的解释:

  1. @GeneratedValue注解中,生成器属性是在以下注解中定义的逻辑名称。
  2. @SequenceGenerator注解中,sequenceName属性是数据库序列的实际名称,name属性是对上述生成器逻辑名称的解析

此外,这些链接 ( Link1 Link2 ) 可能会对您有所帮助。

于 2019-11-29T10:41:01.290 回答