Showing posts sorted by relevance for query Hibernate. Sort by date Show all posts
Showing posts sorted by relevance for query Hibernate. Sort by date Show all posts

Hibernate SQL Dialects List

Hibernate SQL Dialects List

In this post, I would like to listed out hibernate supported Dialects. Actually based on our application requirement we use this Dialect classes in configuration file (hibernate.cfg.xml) to set the property hibernate.dialect.
Hibernate SQL Dialects (hibernate.dialect)

RDBMS                                                         Dialect

DB2                                                    org.hibernate.dialect.DB2Dialect
DB2 AS/400                                        org.hibernate.dialect.DB2400Dialect
DB2 OS390                                         org.hibernate.dialect.DB2390Dialect
PostgreSQL                                        org.hibernate.dialect.PostgreSQLDialect
MySQL5                                             org.hibernate.dialect.MySQL5Dialect
MySQL5 with InnoDB                           org.hibernate.dialect.MySQL5InnoDBDialect
MySQL with MyISAM                          org.hibernate.dialect.MySQLMyISAMDialect
Oracle (any version)                            org.hibernate.dialect.OracleDialect
Oracle 9i                                            org.hibernate.dialect.Oracle9iDialect
Oracle 10g                                         org.hibernate.dialect.Oracle10gDialect
Oracle 11g                                         org.hibernate.dialect.Oracle10gDialect
Sybase                                              org.hibernate.dialect.SybaseASE15Dialect
Sybase Anywhere                               org.hibernate.dialect.SybaseAnywhereDialect
SAP DB                                             org.hibernate.dialect.SAPDBDialect
Informix                                              org.hibernate.dialect.InformixDialect
HypersonicSQL                                  org.hibernate.dialect.HSQLDialect
H2 Database                                      org.hibernate.dialect.H2Dialect
Ingres                                                org.hibernate.dialect.IngresDialect
Progress                                            org.hibernate.dialect.ProgressDialect
Mckoi SQL                                        org.hibernate.dialect.MckoiDialect
Interbase                                           org.hibernate.dialect.InterbaseDialect
Pointbase                                          org.hibernate.dialect.PointbaseDialect
FrontBase                                          org.hibernate.dialect.FrontbaseDialect
Firebird                                              org.hibernate.dialect.FirebirdDialect
Microsoft SQL Server 2000                  org.hibernate.dialect.SQLServerDialect
Microsoft SQL Server 2005                  org.hibernate.dialect.SQLServer2005Dialect
Microsoft SQL Server 2008                  org.hibernate.dialect.SQLServer2008Dialec

Hibernate Configuration File-(hibernate.cfg.xml)

In this post, we are going to discus about how prepare the hibernate configuration file and what is the purpose of this file.

The hibernate framework requires this, because, hibernate needs to know which database system is communicate at run time to perform persistence operations.
In hibernate.cfg.xml, we configure all data base related information to hibernate by using some hibernate properties. we discuss later about these all properties which supported in configuration file. Now we discuss some properties which requires by our application.
Properties:
hibernate.connection.driver_class: It specifies the name of the database Driver Class.
hibernate.connection.url: It specifies the database URL connection.
hibernate.connection.username:It specifies the database username.
hibernate.connection.password: It represents database user account password.
dialect: dialect is used to provide database related information to hibernate system for generating SQL queries to specific database.
show_sql: This property is used to set true when we require to show sql query in console at time of application execution

The following screen shot explains all the above properties and how to configure in configuration file.




Note: 
1.The above properties is also used without specifying hibernate.
ex: hibernate.connection.driver_class and connection.driver_class both is used alternatively.
2. We copy the hibernate.cfg.xml from hibernate distribution file. You just copy the both hibernate.cfg.xm and log4j.properties file fromhibernate-distribution file and copy into the Our application root folder.

Location:
D:\softwares-hibernate\hibernate-distribution-3.3.2.GA-dist\hibernate-distribution-3.3.2.GA\project\tutorials\web\src\main\resources

Steps to Design Hibernate Application

Steps to Design Hibernate Application
1. Design POJO class (Greet.java) Prepare a POJO class with setter and getter methods.
package com.becbe.hibernate.ch1;
public class Greet {

      private long id;

      private String greetmsg;

      public Greet(){}

      public long getId() {

            return id;

      }

      public void setId(long id) {

            this.id = id;

      }

      public String getGreetmsg() {

            return greetmsg;

      }

      public void setGreetmsg(String greetmsg) {

            this.greetmsg = greetmsg;

      }



}
2. Write mapping file (Greet.hbm.xml)







      

            

                  

            

            
    

      

3. Write Configuration file (hibernate.cfg.xml)













com.mysql.jdbc.Driver

jdbc:mysql://localhost:3306/mysql

root

root

org.hibernate.dialect.MySQLDialect

true

create








4. To design a Testclass (TestGreet.java)
1. Create a Configuration Object. 2. Create a SessionFactory Object by using buildSessionFactory() from Configuration Object. 3. Create a Session Object by using SessionFactory Object openSession() method. 4. Get Transaction object by using beginTransaction() from Session object.
package com.becbe.hibernate.ch1;

import java.util.ArrayList;

import java.util.List;



import org.hibernate.SessionFactory;

import org.hibernate.Transaction;

import org.hibernate.cfg.Configuration;

import org.hibernate.classic.Session;



public class TestGreet {

   

      public static void display(Greet g)

      {

            System.out.println("List Of MSG in GREET Table");

      System.out.println(g.getGreetmsg());

   

      }



      /**

       * @param args

       */

      public static void main(String[] args) {

      SessionFactory sf=new Configuration().configure().buildSessionFactory();

      Session s=sf.openSession();

      Transaction tx=s.beginTransaction();

      Greet g=new Greet();

      g.setGreetmsg("hi sree h ru");

      s.save(g);

      tx.commit();

      s.close();

      Session s1=sf.openSession();

      Greet g1=(Greet)s1.load(Greet.class,2L);

      TestGreet.display(g1);

      s1.close();

   

      }



}

Eclipse plugin for Hibernate2.x application development

Eclipse plugin for Hibernate2.x application development

Hibernate provides an Eclipse to common Hibernate tasks such as Creating / Updating a Database Schema, running Hibernate queries and creating simple Hibernate Mapping documents

Note this plugin will only work with Eclipse 2 (WSAD 5) and above. Queries and Schema features are Hibernate2 only
Installation:

Unzip hibernator-0.9.x.zip into /plugins
If you downloaded hibernator-0.9.x-nolibs.zip then you will need to add the following .jars that come with Hibernate - xml-apis.jar - commons-beanutils.jar - commons-collections.jar - commons-lang.jar - commons-logging.jar - dom4j.jar - hibernate2.jar - odmg.jar - cglib.jar
Restart Eclipse
Connecting to a Database:

Open Hibernate Perspective
Right click in connection view and select "Add"
Select one or more projects from the list (All *.hbm.xml documents in the selected projects are Configured into Hibernate)
Click next and enter the Database details (I will change this so you can select a hibernate.properties file instead)
Click finish
Click on the Hibernate Log View
Select and right click on the new connection. Click on "Connect!"
Confirm the mappings and connection are ok in the Log View - Simply hit "Connect!" on any other connections to prepare them for Query or Schema Update/Create
 Running a query:

Make sure you have created and connected to a database as above
Type your query into the "Query View" and hit "Execute"
Not the table of results in the "Results View" or any errors in the "Log View"
Updating / Creating Schema:

Make sure you have created and connected to a database as above
Click on Create or Update Schema in the "Query View"
Note the results in the "Log View"

 Creating a simple mapping document:

Go to menu Window->Show View->Other and select Hibernator
Open up some Java source and the plugin will either display the mapping file .hbm.xml or a generated version
To save the contents of the mapping file right click in the window and select "Save"

Download the latest (0.9) from - http://sourceforge.net/projects/hibernator
Report any bugs / Submit patches to - http://sourceforge.net/projects/hibernator 


Original code from

Christopher (Jozsa Kristof) dyn@on... (that's all the Sourceforge lists will show me)
Contributions from
Gavin King
Daniel Bradby

Hibernate Framework

Hibernate Framework

Hibernate Framework

Hibernate framework simplifies the development of java application to interact with the database. Hibernate is an open source, lightweight, ORM (Object Relational Mapping) tool.
It act as a bridge between Objects and relational data base. Hibernate maps objects with relation.An ORM tool simplifies the data creation, data manipulation and data access.
It is a programming technique that maps the object to the data stored in the database.
hibernate tutorial, An introduction to hibernate
The ORM tool internally uses the JDBC API to interact with the database.

Hibernate 3.2.GA Setup JAR files-Hibernate appliactions

Hibernate 3.2.GA Setup JAR files-Hibernate appliactions

In this article, I would like to discus about Hibernate setup JAR files and Explain the steps to create User Library in Eclipse.


To execute the hibernate applications what I, develop in this blogger we need to set the following JAR  files in to class path.

The Required JAR files are listed below:

  •  antlr-2.7.6.jar
  •  asm.jar
  •  commons-collections-3.1.jar
  •  commons-collections.jar
  •  dom4j-1.6.1.jar
  •  dom4j.jar
  •  ejb3-persistence.jar
  •  hibernate-annotations.jar
  •  hibernate3.jar
  •  javassist-3.9.0.GA.jar
  •  jta-1.1.jar
  •  jta.jar
  •  junit.jar
  •  log4j.jar
  •  mysql-connector-java-5.1.16-bin.jar
  •  slf4j-api-1.5.8.jar
  •  slf4j-api.jar
  •  slf4j-log4j12.jar
The above mentioned jar files which supports to develop both JPA (Java Persistence API) Annotations and XML based hibernate applications.

In next chapter we discus about how to create User library and Database support in Eclipse IDE.

Steps to Download ECLIPSE+Hibernate+MySQL


1.     Download Eclipse IDE for Java EE Developers
  

1.1. Click on Downloads





  

















 1.2. Choose Windows 32-bit or  64-bit Downloads






























2.     Download Hibernate 3.2 Distribution and Annotation JAR files.
        http://www.hibernate.org
 2.1. Click on Downloads     
  



2.2. Download hibernate 3.3.2.GA Distribution

         
 
       

    2.3. Download hibernate annotation 3.4. GA

      
       


3.     Steps to download MySQL 5.x

        http://www.mysql.org

  3.1. Click on Downloads   
              
               
        3.2. Click on MySQL Community Server    

       


3.3.   Click to download MySQl


 

3.4. Download Connector /J file






Note: Download and copy hibernate related jar files into separate folder for our program reference.



Steps to prepare mapping files.-Greet.hbm.xml


The mapping files are required by the hibernate framework during execution to map POJO class with Database table. Mapping file consist the information about which POJO class is actaually mapped with which database table

In this article we discus about how to write hibernate mapping file for POJO classes. First we follow these steps 
1. Create a new xml file with name (Greet.hbm.xml)

 

 2. Write the following code in mapping file.




Note: When we prepare mapping file, you just copy the mapping file from hibernate distribution file and do changes according to our applications. Once you extract the jar file, then you find some hbm files in the following locations

Ex:D:\hibernate-distribution-3.3.2.GA-dist\hibernate-distribution-3.3.2.GA\project\tutorials\eg\src\main\resources\org\hibernate\auction

Steps to create UserLibrary in Eclipse IDE

User Library:
Normally if you develop any hibernate related applications we need to setup required jar files in to System class path. Suppose if we develop applications using IDE , we need to copy the list of required JAR files into lib folder for each applications separately. To overcome this problem by creating user libraries.

1.Select Window->Preferences


2. Enter Name for UserLibrary.
 
3. Add required JAR files into the UserLibrary.


 



  4. Add Hibernate Annotations JAR files.
   
   
  
5. Add MySQL database Connector/J jar file for MySQL Database Support

 

 In next post we discuss about how to setup the database development environment  in Eclipse IDE

Hibernate How split string by charcter ( using Java

Hibernate  How split string by charcter ( using Java

/**
*
*/
package com.onlinecodegeek.java.string.ex;

/**
* @author tponnam
*
*/
public class SplitStringDemo {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String demoText="hello(world(Welcome(Java";
String temp[] = demoText.split("\\(");
for(String text:temp){
System.out.println(text);
}

}

}

Output:


hello
world
Welcome
Java

 

Steps to create Simple Hibernate Application using Eclipse IDE


1. Create a new Java Project.
 
 2. Enter Project Name


 3. Create and add Java class to application.

 
4. Enter Package and a Java Class name.

5. Develop Greet class.
 Steps to generate Setter and getter methods for properties.

 



 

 For next post we discus about how create mapping files for  POJO class.