【问题标题】:JPA/Hibernate works with Postgresql, but not with MysqlJPA/Hibernate 适用于 Postgresql,但不适用于 Mysql
【发布时间】:2012-04-14 08:21:05
【问题描述】:

我正在尝试用 MySQL 替换我的应用程序中的 PostgreSQL。我认为替换persistence.xml文件中的<properties>就足够了:

PostgreSQL:

<property name="hibernate.connection.url" value="jdbc:postgresql://localhost/postgres"/>
<property name="hibernate.connection.username" value=""/>
<property name="hibernate.connection.password" value=""/>
<property name="hibernate.connection.driver_class" value="org.postgresql.Driver"/>
<property name="hibernate.show_sql" value="true"/>

MySQL:

<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
<property name="hiberante.connection.url" value="jdbc:mysql://localhost:3306/GoOut2"/>
<property name="hibernate.connection.username" value=""/>
<property name="hibernate.connection.password" value=""/>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
<property name="hibernate.hbm2ddl.auto" value="update"/>

但是有了这个替换,我得到了

java.lang.UnsupportedOperationException: The application must supply JDBC connections

我不确定我做错了什么,我只是希望替换会很简单。在 PostgreSQL 中,一切正常。

Persistence.xml:https://gist.github.com/2252443

applicationContext.xml:https://gist.github.com/2252463

例外:https://gist.github.com/2252487

谢谢!

编辑: 我故意从给​​定的代码中删除用户名和密码。

【问题讨论】:

  • 你也可以发布会话工厂的启动消息吗?
  • 您可以使用给定的凭据信息从 mysql 工作台连接吗?

标签: java mysql hibernate postgresql jpa


【解决方案1】:

您缺少 PostgreSQL 的配置休眠方言:

<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/>

编辑:

您在配置中缺少拼写:

<property name="hiberante.connection.url" value="jdbc:mysql://localhost:3306/GoOut2"/>

应该是

<property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/GoOut2"/>

hibernate,但不是hiberante

【讨论】:

  • 我只是忘记将它添加到示例中,但我的问题不是 PostgreSQL,而是 MySQL。
【解决方案2】:
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
        <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/demo</property>
        <property name="hibernate.connection.username">root</property>
        <property name="hibernate.connection.password">root</property>

【讨论】:

    猜你喜欢
    • 2020-09-13
    • 1970-01-01
    • 2021-06-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-24
    相关资源
    最近更新 更多