gpt4 book ai didi

java - org.springframework.dao.DataIntegrityViolationException : could not execute statement; SQL [n/a]; constraint [admin_pkey]; 错误

转载 作者:行者123 更新时间:2023-11-29 13:51:44 25 4
gpt4 key购买 nike

我能够成功地将数据插入到 mysql 数据库中,现在我将数据库切换到 postgresql 并且我遇到了这个挑战

org.springframework.dao.DataIntegrityViolationException: could not execute statement; SQL [n/a]; constraint [admin_pkey]; nested exception is org.hibernate.exception.ConstraintViolationException: 
could not execute statement

我已确保对我的 id 列进行 generation_auto 注释,但错误仍然存​​在,这是我的类映射

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id")
private Integer id;

@Column(unique = true, nullable = false)
private String name;

@Column(unique = true, nullable = false)
private String email;

@Column(unique = false, nullable = false)
private String password;

@Column(unique = false, nullable = false)
private Date date;

public Integer getId() {
return id;
}

最佳答案

如果您要更改数据库,那么您也应该相应地更改 hibernate 配置 XML。
这是 hibernate.cfg.xml :

<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
<session-factory>
<property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
<property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
<property name="hibernate.connection.username">postgres</property>
<property name="hibernate.connection.password">password</property>
<property name="hibernate.connection.url">jdbc:postgresql://localhost:5432/hibernatedb</property>

<property name="connection_pool_size">1</property>

<property name="hbm2ddl.auto">create</property>

<property name="show_sql">true</property>

<mapping class="org.sample"/>

</session-factory>
</hibernate-configuration>

关于java - org.springframework.dao.DataIntegrityViolationException : could not execute statement; SQL [n/a]; constraint [admin_pkey]; 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39769360/

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