gpt4 book ai didi

java - JPA DDL生成异常

转载 作者:行者123 更新时间:2023-11-29 10:01:16 33 4
gpt4 key购买 nike

我有以下实体

@Data
@EqualsAndHashCode(callSuper = false)
@Entity
@Table(name = "REF_CLIENT")
@IdClass(RefClientID.class)

@NamedNativeQueries({@NamedNativeQuery(name = "RefClient.updateByClicincli", query = "UPDATE REF_CLIENT rc "
+ "SET rc.clicexcli = :clicexcli , rc.cliidclient=:cliidclient ,"
+ "rc.cliemail=:cliemail, rc.clitypcli=:clitypcli ," + "rc.clietatcli=:clietatcli"
+ " WHERE rc.clicincli = :clicincli ;")})
public class RefClient extends CommonData implements Serializable {

private static final long serialVersionUID = 4763218211813908401L;

/**
* N X NUMBER Code interne client
*/
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "CLICINCLI", unique = true, updatable = false, nullable = false)
private Long clicincli;

/**
* N X VARCHAR2(13) Code externe client
*/
@Id
@GeneratedValue(strategy=GenerationType.SEQUENCE, generator = "system-uuid")
@GenericGenerator(name = "system-uuid", strategy = "uuid")
@Column(name = "CLICEXCLI", unique = true, length = 13, nullable = false)
private String clicexcli;

ID类如下

@Data
public class RefClientID implements Serializable {

/**
*
*/
private static final long serialVersionUID = 1932584805198196159L;

/**
* N X VARCHAR2(13) Code externe client
*/
private String clicexcli;

/**
* N X NUMBER Code interne client
*/
private Long clicincli;

}

日志中生成的DDL是

Hibernate: create table ref_client (clicexcli varchar(13) not null auto_increment, clicincli bigint not null, datcre DATE DEFAULT CURRENT_DATE not null

如您所见,VARCHAR 无法自动递增,如何解决此问题?

我尝试删除身份策略,ddl 工作正常,但没有 clicincli 的 auto_increment,如果我重用它,它将在 String 字段 clicexcli 中生成 auto_increment,并且 Long 字段 (clicincli) 中不会有 auto_increment

最佳答案

由于@GenerateValue注解中ID生成的默认策略GenerationType.AUTO,我们必须手动将其更改为SEQUENCE 当我们使用生成器时。

我会将您的代码更改为:

    @Id
@GeneratedValue(strategy=GenerationType.SEQUENCE, generator = "system-uuid")
@GenericGenerator(name = "system-uuid", strategy = "uuid")
@Column(name = "CLICEXCLI", unique = true, length = 13, nullable = false)
private String clicexcli;

您可以在 Oracle documentation 中查看

Default: javax.persistence.GenerationType.AUTO

关于java - JPA DDL生成异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52907269/

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