110 likes | 444 Views
Hibernate. Netbeans-Database-Hibernate Downloads. Download Jdk and install Download Java IDE ( Netbeans ,Eclipse) Setup a Database ( Postgresql , MySQL , Oracle ..) Download hibernate files from http :// sourceforge.net/projects/hibernate/files/ hibernate Core hibernate annotations.
E N D
Netbeans-Database-Hibernate Downloads • Download Jdk and install • Download Java IDE (Netbeans,Eclipse) • Setup a Database (Postgresql,MySQL,Oracle..) • Download hibernate files from http://sourceforge.net/projects/hibernate/files/ • hibernate Core • hibernate annotations
How to configure? MySQL Database Netbeans User Library hibernate.cfg.xml Hibernate
User library Required Libraries antlr-2.7.6.jar cglib.jar commons-collections.jar dom4j.jar ejb-3-persistence hibernate-annotation.jar hibernate-commons-annotation.jar hibernate3.jar javassist-3.9.0.GA.jar jta-1.1.jar log4j.jar slf4j-api-1.5.8.jar slf4j-log4j12.jar // and database connector mysql-connector-java-5.1.13-bin.jar • User library is a folder for required hibernate jar files • In your IDE: • create a Hibernate "library" • add JARs to the library • better than copying JAR files to your project
Create a Hibernate Library in Eclipse 1. Tools -> Libraries 3. Click "Add Library..." and select "User Library", Next> 4. Create a new user library named "Hibernate" 5. Add Jar files
hibernate.cfg.xml • hibernate.cfg.xml • Customize, • <!-- Database connection settings --> • <!-- SQL dialect --> • <!-- Enable Hibernate's current session context --> (thread) • Make comment <!-- Drop and re-create the database schema on startup --> and 2 mapping lines
example • Example 1: Employee Example • Setup Eclipse-Database-Hibernate • Create a table out of a class • Insert an object as a record • Example 2 : Employee Example • Other annotations • Generate primary key
Example • Example 3 : how to split one class to two tables • Example 4 : two classes one table • Example 5 : compound primary key • Example 6 : inheritance mapping • Example 7: one to one mapping • Example 8: one to many • Example 9: many to many