Archive for category Hibernate

Difference Hibernate & JPA

Hibernate JPA
SessionFactory EntityManagerFactory
Session EntityManager
sessionFactory.getCurrentSession().[method]() entityManager.[method]()
saveOrUpdate() persist()
Query.setInteger/String/Entity() Query.setParameter()
list() getResultList()
uniqueResult() getSingleResult()
uniqueResult() returns null getSingleResult() throws NoResultException
CriteriaQueries – yes CriteriaQueries – no

Reference:
http://tech-blog.milestoneinc.com/differences-between-hibernate-and-jpa

,

Leave a comment

Hibernate Tutorial Best Link

Hibernate:

http://viralpatel.net/blogs/2011/11/introduction-to-hibernate-framework-architecture.html

http://docs.jboss.org/hibernate/core/4.1/javadocs/

 

For JPA:

http://download.oracle.com/otndocs/jcp/persistence-2.0-fr-eval-oth-JSpec/

http://www.objectdb.com/api/java/jpa

http://docs.oracle.com/javaee/6/api/javax/persistence/package-summary.html

,

1 Comment

Create Schema Using Hibernate

Getting Hibernate to Create Schema Creation SQL

I’ve seen some webpages that describe the SchemaExport Ant task. But it did not work when I tried to use it. The documentation for it was sparse. In any case, I traced through the underlying Hibernate code and found out that you can generate the schema creation SQL with just three lines of code:

package com.codebits;

import java.io.File;

import org.hibernate.cfg.Configuration;
import org.hibernate.dialect.PostgreSQLDialect;

public class Play {

 public static void main(String[] args) {
  Configuration cfg = new Configuration();
  cfg.addDirectory(new File("config"));
  String[] lines = cfg.generateSchemaCreationScript(new PostgreSQLDialect());

  for (int i = 0; i < lines.length; i++) {
   System.out.println(lines[i] + ";");
  }
 }

}

Place your .hbm.xml files into some directory (I called mine config) and then execute the above class. Your schema creation script will be displayed on the console.

Reference:

http://affy.blogspot.in/2006/04/getting-hibernate-to-create-schema.html

,

Leave a comment

Hibernate

On Progress…

,

Leave a comment