views:

170

answers:

1

Hi, I have some basic questions:

1) How many xml files involved in JPA+Hibernate combination, 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!

+5  A: 

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&lt;/url&gt;
  </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.

seanizer
I would just add that if you're not using Maven, you should get [release bundles](http://sourceforge.net/projects/hibernate/files/hibernate3/) from SourceForge. +1 anyway of course.
Pascal Thivent
@Pascal thanks, added that link to my answer
seanizer