【问题标题】:Java SQLite Foreign Keys with Hibernate带有 Hibernate 的 Java SQLite 外键
【发布时间】:2013-07-17 18:39:37
【问题描述】:

我正在使用带有 SQLite 的 Hibernate。我面临的挑战是启用外键。 我尝试在连接 url 中传递 PRAGMA 命令,但没有成功。

查看 SQLite 驱动程序,我可以看到有一个构造函数,它接受一个 Properties 对象,该对象设置任何提供的 PRAGMA。如何使用 Hibernate 传递此参数?

依赖关系

  • Xerial - sqlite-jdbc-3.7.2.jar
  • Hibernate-jpa-2.0-api-1.0.0.Final.jar
  • Hibernate-entitymanager-4.2.2.Final.jar
  • Hibernate-core-4.2.2.Final.jar

谢谢

【问题讨论】:

    标签: java hibernate sqlite


    【解决方案1】:

    我设法通过修改persistence.properties 文件让它工作。 我在 persistence.properties 文件中添加了以下属性:

    hibernate.connection.foreign_keys=true
    

    我可以看到该属性正在传递给控制台中的连接。

    HH000046: Connection properties: {user=, password=****, autocommit=true, foreign_keys=true, release_mode=auto}
    org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl
    

    【讨论】:

      猜你喜欢
      • 2021-09-04
      • 1970-01-01
      • 1970-01-01
      • 2010-12-19
      • 2017-06-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-04
      相关资源
      最近更新 更多