Hibernate-Netbeans Connectionx

streakconvertingSoftware and s/w Development

Dec 13, 2013 (3 years and 8 months ago)

62 views

H
IBERNATE

N
ETBEANS
-
D
ATABASE
-
H
IBERNATE

D
OWNLOADS

1.
Download Jdk and install

2.
Download Java IDE (
Netbeans
,Eclipse)

3.
Setup a Database (
Postgresql
,
MySQL
,
Oracle

..)

4.
Download hibernate files from

http
://
sourceforge.net/projects/hibernate/files/


hibernate Core


hibernate annotations


H
OW

TO

CONFIGURE
?


Netbeans

Database

Hibernate

MySQL

User Library

hibernate.cfg.xml


U
SER

LIBRARY


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

Required Libraries

antlr
-
2.7.6.jar

cglib.jar

commons
-
collections.jar

dom4j.jar

e
jb
-
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

m
ysql
-
connector
-
java
-
5.1.13
-
bin
.jar

C
REATE

A

H
IBERNATE

L
IBRARY

IN

E
CLIPSE

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


E
XAMPLE


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