Reputation: 309
Hi I am new to hibernate. I read a lot of threads and discussions about which book and what specification to read. But the problem is some threads are so old that I don't understand where to start from. I started with Hibernate specification in Developer Guide which I think is too complicated. So I read some small tutorials. Actually I am assigned to some project where I was told that Hibernate is used. But because of little knowledge about Hibernate I am totally lost. In the code I can see that in Maven pom Hibernate is used. I found META-INF/Persistence.xml which contains:
<?xml version="1.0" encoding="UTF-8" ?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" version="1.0">
<persistence-unit name="EmployeeDatabase" transaction-type="JTA">
<jta-data-source>java:EmpDS</jta-data-source>
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>entity.Employee</class>
<properties>
<property name="hibernate.connection.password" value="Usha" />
<property name="hibernate.archive.autodetection" value="class" />
<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver" />
<property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/Employee" />
<property name="hibernate.connection.username" value="Usha" />
<property name="hibernate.hbm2ddl.auto" value="update" />
<property name="hibernate.show_sql" value="false" />
</properties>
</persistence-unit>
I thought for hibernate configuration has to be done through hibernate.cfg.xml. But I coulnt find it anywhere. And in the code while doing queries there was no reference to hibernate. All the queries were done using import javax.persistence.Query. So I guess JPQL is used for doing the queries.
So my question is : Is this really Hibernate or JPA or what??
When can i say this is using Hibernate for persistence.
When to use JPQL and when to use HQL?
Please please can anyone guide me through this. Just be clear I want to learn Hibernate first and then dig further into my assignment. But I do not know where to start from. Which book or tutorial is best .
Best Regards, Jeena
Upvotes: 0
Views: 288
Reputation: 6712
Hibernate is an implemantation for JPA. But Hiberante has more. There are other ways in hibernate to persist your objects to database. As mantioned, you can use JPA with other frameworks like myBatis.
In Hibernate using JPA is one option. When using JPA option you must use EntityManager
and EntityManagerFactory
. You must build your Factories using persistance.xml
.
On the other hand you can use other options like Criteria API
or HQL
. When using Hibernate specific option, you must use Session
and SessionFactory
. And you must use hibernate.cfg.xml
when creating your SessionFactory.
Upvotes: 1
Reputation: 1312
So my question is : Is this really Hibernate or JPA or what??
This is JPA that uses Hibernate as implementation.
JPA is a standard, Hibernate is one of the implementation of JPA standard
Try to follow Hibernate documentation and tutorial, then use Hibernate EntityManager to make your project JPA compliant
Upvotes: 2
Reputation: 10342
Is this really Hibernate or JPA or what?
JPA is a framework and Hibernate is an implementation that can use JPA framework. So do not confuse those together.
When to use JPQL and when to use HQL?
Again JPQL is a standard language and is not only tied to Hibernate. However, if you are only using Hibernate you might find HQL to have more options and be more flexible.
http://en.wikipedia.org/wiki/Java_Persistence_Query_Language refer to this:
JPQL is based on the Hibernate Query Language (HQL), an earlier non-standard query language included in the Hibernate object-relational mapping library.
Hibernate and the HQL were created before the JPA specification. As of Hibernate 3 JPQL is a subset of HQL.
Upvotes: 5