JPA 配置到底是什么?
我疯狂地试图让一个简单的 Envers 示例工作。 我被困在 org.hibernate.tool.ant.EnversHibernateToolTask 上 - 看起来我终于得到了我需要的所有 jar 文件,但现在我收到了错误消息
[hibernatetool] Persistence unit not found: 'ConsolePU'.
BUILD FAILED
C:\deka\proj\java\test-database\build.xml:61: Persistence unit not found: 'ConsolePU'.
据我所知,持久性单元与 JPA persistence.xml
文件关联。 但我没有使用 persistence.xml 文件; 我正在使用 hibernate.cfg.xml — 但 envers 示例在 ant 任务中有一个
:
<hibernatetool destdir=".">
<classpath>
<fileset dir="src/">
<include name="**/*.hbm.xml"/>
</fileset>
<path location="${buildDir}" />
</classpath>
<jpaconfiguration persistenceunit="ConsolePU" />
<hbm2ddl
drop="false"
create="true"
export="false"
outputfilename="versioning-ddl.sql"
delimiter=";"
format="true"/>
</hibernatetool>
是否有一些我可以替换它的东西,以使其能够与 hibernate 一起工作。 cfg.xml 文件? 关于如何让所有这些东西正常工作的文档似乎为零。
编辑:好的,主要问题是我不了解 hibernatetool 选项以及什么适合我的应用程序。 我确实找到了 Hibernate ant 文档,幸运的是。 谢谢。 现在我有一个新问题:我正在使用注释,但我还为属性设置设置了 hibernate.cfg.xml 。 hibernatetool
任务只允许我运行
或
,不能同时运行,甚至
不会工作,因为我已经有注释在做事情了。 如何将属性设置从 hibernate.cfg.xml 文件迁移到注释?
编辑:呃,我没有意识到你只是这样做:
<annotationconfiguration configurationfile="...filename..." />
I'm going nuts trying to get a simple Envers example to work. I'm stuck on the org.hibernate.tool.ant.EnversHibernateToolTask
— it looks like I finally got all the jar files I needed, but now I get the error message
[hibernatetool] Persistence unit not found: 'ConsolePU'.
BUILD FAILED
C:\deka\proj\java\test-database\build.xml:61: Persistence unit not found: 'ConsolePU'.
As far as I can tell, persistence units are associated with JPA persistence.xml
files. But I'm not using a persistence.xml file; I'm using hibernate.cfg.xml — but the envers example has a <jpaconfiguration>
in the ant task:
<hibernatetool destdir=".">
<classpath>
<fileset dir="src/">
<include name="**/*.hbm.xml"/>
</fileset>
<path location="${buildDir}" />
</classpath>
<jpaconfiguration persistenceunit="ConsolePU" />
<hbm2ddl
drop="false"
create="true"
export="false"
outputfilename="versioning-ddl.sql"
delimiter=";"
format="true"/>
</hibernatetool>
is there something that I can replace it with to get it to work with the hibernate.cfg.xml file? There seems to be ZERO documentation on how to get all this stuff to work properly.
edit: OK, so the main problem was I didn't understand the hibernatetool options and what was appropriate for my app. I did find the Hibernate ant docs, fortunately. Thanks. Now I have a new problem: I'm using annotations, but I also have set up a hibernate.cfg.xml for the properties settings. The hibernatetool
task only lets me run either <configuration />
or <annotationconfiguration />
not both, and even <configuration />
won't work since I already have annotations doing things. How can I migrate my property settings from the hibernate.cfg.xml file to my annotations?
edit: Duh, I didn't realize you just do:
<annotationconfiguration configurationfile="...filename..." />
per the hibernatetool task docs.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
将
替换为
标签,详见 Hibernate Tools 文档:Replace the
<jpaconfiguration />
with the<configuration />
tag, as detailed in Hibernate Tools docs:只是为了给您高水平的视角。
JPA是SUN提供的标准持久化API。
您可以使用任何持久性框架(如 Hibernate、TopLink、JDO 等)作为 JPA 的持久性提供
。
程序 JPA -----> 持久化提供者(Hibernate)。
使用 JPA 是一个很好的做法,因为它是标准库。
因此,您的持久性提供程序信息应该只有 JPA 知道,而不是您的代码特定的 XML。
这就是你的 persistence.xml 的样子
,你的应用程序上下文的样子(依赖于 JPA ,没有提到 Hibernate)
Just to give you high level prespective.
JPA is standard persistence API provided by SUN.
You can use any persistence framework like Hibernate,TopLink,JDO etc as persistence provider with JPA.
So just to make things clear
Your code -----> JPA ----->Persistence Provider(Hibernate).
Its will be good practice to use JPA as it is standard library.
So what is your persistence provider information should only be known to JPA and not your code specific XML's.
This is how your persistence.xml will look like
And your Application context will look like (Dependent on JPA , no mention of Hibernate)
您需要从头开始:Sun 的 JPA 教程。
这也可能有帮助。
您需要创建 persistence.xml 并将其放入项目的 META-INF 目录中。
Hibernate 是JPA 的一种具体实现,但还有其他实现(例如JDO)。
You need to start at the beginning: Sun's JPA tutorial.
This might help as well.
You need to create the persistence.xml and put it in the META-INF directory for your project.
Hibernate is one concrete implementation for JPA, but there are others (e.g., JDO).
您需要注释配置而不是 jpa 配置。
You need annotationconfiguration not jpaconfiguration.