【问题标题】:How to use JPA annotations in ormlite?如何在 ormlite 中使用 JPA 注释?
【发布时间】:2012-10-09 11:54:49
【问题描述】:

我想在 ormlite 中使用 JPA 注释。这些注释(如@Entity 或@Id)属于 javax.persistence 包,它显然没有随 ormlite 提供。我无法解析 JPA 注释,而 ormlite 特定注释(如@DatabaseTable)可以。我是否需要下载第三方 jar 才能让 JPA 注释在 ormlite 中工作?

我只需要使用 ormlite + JPA。

查看http://ormlite.com/javadoc/ormlite-core/index-all.html 时,我们可以看到没有记录或可用的 JPA 注释,尽管它们在用户手册中有所描述。

提前非常感谢!!!

【问题讨论】:

    标签: jpa ormlite


    【解决方案1】:

    javax.persistence 在来自central maven repository 的 jar 中可用(例如)。它包含所有注释以及 ORMLite 忽略的所有其他 JPA 内容。

    【讨论】:

      【解决方案2】:

      CMobileCom JPA 是 JPA 规范的新实现,适用于 Java JDBC 和 Android。它是轻量级的,大约 380K。您可以添加以下 gradle 依赖项:

      安卓:

      dependencies {
          implementation("com.cmobilecom:cmobilecom-jpa-android:${version}@aar") {
              transitive = true
          }
      
          annotationProcessor "com.cmobilecom:cmobilecom-jpa-processor:$version"
      }
      

      Java JDBC:

      dependencies {
          implementation "com.cmobilecom:cmobilecom-jpa-jdbc:$version"
          
          // annotation processor: generate static metamodel
          compileOnly "com.cmobilecom:cmobilecom-jpa-processor:$version"
      }
      

      支持 JPA 注释,因此您无需添加另一个 jar 来解析代码中的 JPA 注释。

      参见开发者指南:

      https://cmobilecom.com/docs/jpa/latest/devguide/index.html

      免责声明:我是CMobileCom JPA的开发者。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-04-22
        • 1970-01-01
        • 2021-05-17
        • 2011-05-05
        • 2017-12-18
        • 2021-11-03
        相关资源
        最近更新 更多