如何在ormlite中使用JPA注释?

问题描述 投票:4回答:2

我想在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
2个回答
4
投票

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


0
投票

CMobileCom JPA是Java JDBC和Android的JPA规范的新实现。它重量轻,约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的开发人员。

© www.soinside.com 2019 - 2024. All rights reserved.