Tuesday, June 11, 2013

Hibernate note

Hibernate note (4.2.2)
1. Download hibernate-release-4.2.2.Final and hibernate-orm-master.zip (source code)
2. Download hibernate-tutorials.zip and import into Eclipse
3. Run NativeApiIllustrationTest
4. Update hibernate.cfg.xml to based on oracle
5. Update NativeApiIllustrationTest to not use deprecated method:
  Configuration config = new Configuration().configure();//invoke configure to use hibernate.cfg.xml
  serviceRegistry = new ServiceRegistryBuilder().applySettings(config.getProperties()).buildServiceRegistry();
        sessionFactory = config.buildSessionFactory(serviceRegistry);
6. Remove property hbm2ddl.auto to keep the table
7. Remove Event.hbm.xml to use annotation
8. set Id's column name to EVENT_ID
9. Remove setId from Event to watch the error
10.JPA needs to put hibernate-entitymanager-4.2.2.Final on classpath, or it cannot find the persistence provider. (name does not matter if only it's matched)
11.Enver example will create table EVENTS,EVENTS_AUD,REVINFO and sequence hibernate_sequence
Hibernate may not be the best solution for data-centric applications that only use stored-procedures to implement the business logic in the database,
it is most useful with object-oriented domain models and business logic in the Java-based middle-tier.
The Hibernate Query Language (HQL) and Java Persistence Query Language (JPQL) are both object model focused query languages similar in nature to SQL. JPQL is a heavily-inspired-by subset of HQL. A JPQL query is always a valid HQL query, the reverse is not true however.
You may also express queries in the native SQL dialect of your database. This is useful if you want to utilize database specific features such as query hints or the CONNECT BY option in Oracle. It also provides a clean migration path from a direct SQL/JDBC based application to Hibernate/JPA.
Problem:
Difficult to get the connection from EntityManger. JPA does not define the interface.
The method to get it under hibernate 3,4 and JPA1,2 are different:
http://www.bigdev.org/2012/02/getting-jdbc-sql-connection-in-jpa-with-hibernate/

 

No comments:

Post a Comment