【问题标题】:In Hibernate, hbm2ddl.auto = "update" is inserting records but also giving some exceptions?在 Hibernate 中,hbm2ddl.auto = "update" 正在插入记录但也给出了一些异常?
【发布时间】:2019-02-06 03:08:26
【问题描述】:

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

org.hibernate.tool.schema.spi.CommandAcceptanceException:执行 DDL 时出错“创建表配置文件(用户名 varchar(255)不为空,First_Name varchar(255),Last_Name varchar(255),主键(用户名))”通过 JDBC 语句 在 org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:67) 在 org.hibernate.tool.schema.internal.AbstractSchemaMigrator.applySqlString(AbstractSchemaMigrator.java:559) 在 org.hibernate.tool.schema.internal.AbstractSchemaMigrator.applySqlStrings(AbstractSchemaMigrator.java:504)

引起:net.ucanaccess.jdbc.UcanaccessSQLException: UCAExc:::4.0.4 java.sql.SQLSyntaxErrorException: 对象名已经存在:PROFILES in statement [create table Profiles (username varchar(255) not null, First_Name varchar (255), Last_Name varchar(255), 主键 (用户名))] 在 net.ucanaccess.jdbc.UcanaccessStatement.execute(UcanaccessStatement.java:159) 在 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>

【问题讨论】:

  • 加载 sessionFactory 时是否出现此错误?
  • 是的,没错。
  • 您是否在控制台中获取 sql 查询?
  • 我收到以下错误。执行 DDL 时出错“创建表配置文件(用户名 varchar(255)不为空,First_Name varchar(255),Last_Name varchar(255),主键(用户名))”通过 JDBC 语句我也期望控制台中的查询是 true 的效果,但没有查询。

标签: hibernate


【解决方案1】:

尝试将您的属性重命名为:

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

【讨论】:

  • 添加 &lt;property name="hibernate.temp.use_jdbc_metadata_defaults"&gt; false &lt;/property&gt; 已删除异常.. 但我仍然看不到日志中的 sql 查询。
猜你喜欢
  • 2017-02-24
  • 1970-01-01
  • 2016-01-31
  • 2022-01-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-10-22
相关资源
最近更新 更多