【发布时间】:2011-04-14 16:11:52
【问题描述】:
我有一些基本问题:
1)如果使用JPA注解,JPA+Hibernate组合涉及多少个xml文件?我只有persistence.xml。
2) 如果我使用 JPA 注释,是否需要 hibernate.cfg.xml。因为,我到现在才添加。
3) 如果使用 JPA 2.0 和 Hibernate,谁能给我基本 JAR 文件名的列表!!!
谢谢!
【问题讨论】:
标签: java hibernate orm jpa jpa-2.0
我有一些基本问题:
1)如果使用JPA注解,JPA+Hibernate组合涉及多少个xml文件?我只有persistence.xml。
2) 如果我使用 JPA 注释,是否需要 hibernate.cfg.xml。因为,我到现在才添加。
3) 如果使用 JPA 2.0 和 Hibernate,谁能给我基本 JAR 文件名的列表!!!
谢谢!
【问题讨论】:
标签: java hibernate orm jpa jpa-2.0
1) 涉及多少个xml文件 JPA+Hibernate 组合,如果是 JPA 使用了注释?我有 只是 persistence.xml。
通常这一个文件就足够了,带注释的实体会通过类路径扫描自动拾取。但是您可以定义外部映射文件(例如on this page)。机制是这样的:
<persistence-unit name="xyz">
<mapping-file>../orm.xml</mapping-file>
<!-- ... -->
</persistence-unit>
2) 如果我需要 hibernate.cfg.xml 使用 JPA 注释。因为,我没有 一直添加到现在。
hibernate.cfg.xml 是专有的hibernate 东西,jpa 不需要。
在 JPA 中,您可以使用 <properties> 来配置特定于供应商的属性。示例:
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/>
<property name="hibernate.hbm2ddl.auto" value="create-drop"/>
</properties>
请参阅此文档以获取Hibernate / JPA configuration
3) 谁能给我基本 JAR 文件名的列表,以防使用 JPA 2.0 和休眠!!!
您应该使用maven 并将此依赖项添加到您的 pom.xml:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>3.5.6-Final</version>
</dependency>
(查看this directory 了解最新版本,扫描this file 了解最新出现的*.*.*-Final 或直接阅读Hibernate web site)
您还需要将 JBoss 存储库添加到 pom.xml 或 settings.xml:
<repositories>
<repository>
<id>jboss-public-repository-group</id>
<name>JBoss Public Repository Group</name>
<url>http://repository.jboss.org/nexus/content/groups/public</url>
</repository>
...
</repositories>
这将自动添加所需的所有其他内容,请参阅this previous answer 了解更多详细信息。
如果不想使用maven,可以使用sourceforge提供的release bundles。
【讨论】: