gpt4 book ai didi

java - SequenceGenerator 具有对另一个数据库的自定义查询

转载 作者:行者123 更新时间:2023-12-01 19:48:45 26 4
gpt4 key购买 nike

我使用 SequenceGenerator 和 generatedValue 以及序列“seq_user_hierarchy”在 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;

}

最佳答案

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

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. @GenerateValue注解中,generator属性是在下面的注解中定义的逻辑名称。
  2. @SequenceGenerator注解中,sequenceName属性是数据库序列的实际名称,name属性是对上述逻辑的解析生成器名称

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

关于java - SequenceGenerator 具有对另一个数据库的自定义查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59102688/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com