Some basic JPA + Hibernate questions?

I have some basic questions:

1) How many xml files involved in the JPA + Hibernate combination if JPA annotations were used? I have only persistence.xml.

2) Is hibernate.cfg.xml required if I use JPA annotations. Because, I have not added it so far.

3) Someone will give me a list of the main JAR file names, if using JPA 2.0 and Hibernate !!!

Thanks!

+6
java orm hibernate jpa
source share
1 answer

1) How many xml files involved in JPA + Hibernate if JPA annotations were used? I have just persistence.xml.

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

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

2) Is hibernate.cfg.xml required if I use JPA annotations. Because, I didnt add it so far.

hibernate.cfg.xml is a patented sleeper and is not needed for jpa. In JPA, you can use <properties> to configure the properties of a particular provider. Example:

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

See this document for Sleep / JPA Configuration

3) Someone will give me a list of the main JAR file names, in case of using JPA 2.0 and 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 last appearance *.*.*-Final or just read the Hibernate website )

You also need to add the JBoss repository to the pom.xml or settings.xml file:

 <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> 

which will automatically add everything you need, see this previous answer for more details.

If you do not want to use maven, you can use the release packages provided by sourceforge.

+6
source share

All Articles