作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我能够成功地将数据插入到 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/
我能够成功地将数据插入到 mysql 数据库中,现在我将数据库切换到 postgresql 并且我遇到了这个挑战 org.springframework.dao.DataIntegrityViolat
我是一名优秀的程序员,十分优秀!