开发者

Some basic JPA+Hibernate Questions?

I have some basic questions:

1) How many xml files involved in JPA+Hibernate combination,开发者_如何学C if JPA annotations were used? i am having just persistence.xml.

2) Is hibernate.cfg.xml needed, if i use JPA annotaions. Because, i didnt added it till now.

3) Shall anyone give me the list of basic JAR file names, in case of using JPA 2.0 & Hibernate!!!

Thanks!


1) How many xml files involved in JPA+Hibernate combination, if JPA annotations were used? i am having just persistence.xml.

Usually this one file is enough, annotated entities will be automatically picked up through class path scanning. But you can define external mapping files (an example is available on this page). The mechanism is this:

<persistence-unit name="xyz">
    <mapping-file>../orm.xml</mapping-file>
    <!-- ... -->
</persistence-unit>

2) Is hibernate.cfg.xml needed, if i use JPA annotaions. Because, i didnt added it till now.

hibernate.cfg.xml is proprietary hibernate stuff and not needed for jpa. In JPA, you can use <properties> to configure vendor-specific properties. Example:

<properties>
    <property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/>
    <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
</properties>

See this document for Hibernate / JPA configuration

3) Shall anyone give me the list of basic JAR file names, in case of using JPA 2.0 & Hibernate!!!

you should use maven and add this dependency to your pom.xml:

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-entitymanager</artifactId>
    <version>3.5.6-Final</version>
</dependency>

(see this directory for the latest version, scan this file for the latest occurrence of *.*.*-Final or just read the Hibernate web site)

You will also need to add the JBoss repository to the pom.xml or 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>

that will automatically add everything else that's needed, see this previous answer for more details.

If you don't want to use maven, you can use the release bundles provided by sourceforge.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜