在Hibernate中,hbm2ddl.auto = "update"正在插入记录,但也给出了一些例外?



当我在 hibernate.cfg.xml 文件中提供更新时,当我给出 session.save(( 和 transaction.commit(( 时,对象被保存在数据库中,但仍然在日志中出现一些错误,如下所示。

org.hibernate.tool.schema.spi.CommandAcceptanceException: 通过 JDBC 语句执行 DDL "create table Profiles(用户名 varchar(255( not null, First_Name varchar(255(, Last_Name varchar(255(, 主键 (username((" 时出错 at org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:67( at org.hibernate.tool.schema.internal.AbstractSchemaMigrator.applySqlString(AbstractSchemaMigrator.java:559( at org.hibernate.tool.schema.internal.AbstractSchemaMigrator.applySqlStrings(AbstractSchemaMigrator.java:504(

由: net.ucanaccess.jdbc.UcanaccessSQLException: UCAExc:::4.0.4 java.sql.SQLSyntaxErrorException: 对象名称已存在: 语句中的配置文件 [创建表 配置文件 (用户名 varchar(255( 不为空, First_Name varchar(255(, Last_Name varchar(255(, 主键 (用户名(( ] at net.ucanaccess.jdbc.UcanaccessStatement.execute(UcanaccessStatement.java:159( at org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:54(

我正在使用MS Access db,下面是我的配置文件

<hibernate-configuration>
<session-factory>
<property name="hibernate.dialect">
org.hibernate.dialect.SQLServerDialect
</property>
<property name="hibernate.connection.url">
jdbc:ucanaccess://E:/Eclipse_workspace_trails/DB/messenger.accdb
</property>
<property name="hibernate.connection.driver_class">
net.ucanaccess.jdbc.UcanaccessDriver
</property>
<property name="hbm2ddl.auto">update</property>
<property name="show-sql">true</property>
<mapping resource="hibernate/profiles.hbm.xml"/>
</session-factory>

尝试将属性重命名为:

<property name="hibernate.hbm2ddl.auto">update</property>
<property name="show_sql">true</property>

最新更新