<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Kamil ÖRS &#187; Hibernate</title>
	<atom:link href="http://www.kamilors.com/category/hibernate/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.kamilors.com</link>
	<description>Bir programcının anatomisi</description>
	<lastBuildDate>Fri, 17 Sep 2010 17:04:20 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Hibernate ile derinlemesine &#8211; 1 &#8211; Annotations</title>
		<link>http://www.kamilors.com/hibernate-ile-derinlemesine-1-annotations/</link>
		<comments>http://www.kamilors.com/hibernate-ile-derinlemesine-1-annotations/#comments</comments>
		<pubDate>Wed, 25 Nov 2009 12:06:18 +0000</pubDate>
		<dc:creator>Kamil</dc:creator>
				<category><![CDATA[Hibernate]]></category>
		<category><![CDATA[JEE]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[ejb]]></category>
		<category><![CDATA[j2ee]]></category>
		<category><![CDATA[jpa]]></category>

		<guid isPermaLink="false">http://www.kamilors.com/?p=97</guid>
		<description><![CDATA[Çok uzun zaman önce (1 yılı geçti)  Hibernate&#8217;e Giriş başlıklı bir makale yazmıştım. Oldukça olumlu tepkiler almıştım. Özellikle devamı gelmesi gerektiği hakkında. Ama bir türlü zaman bulup devamını getiremedim. En nihayetinde bugun Hibernate ile Derinlemesine adlı bir yazı dizisine başlamış bulunmaktayım Bu yazıda ( Yazı-1), Hibernate&#8217;e Giriş yazısında anlattığım xml dosyaları ile yapılan eşleştirme işlemi [...]]]></description>
			<content:encoded><![CDATA[<p><img class="img" src="http://www.kamilors.com/files/yazilar/hibernate_logo.gif" alt="" width="146" height="73" align="left" />Çok uzun zaman önce (1 yılı geçti)  <strong><a href="http://www.ceviz.net/hibernatee-giris_a1215.html">Hibernate&#8217;e Giriş</a> </strong>başlıklı bir makale yazmıştım. Oldukça olumlu tepkiler almıştım. Özellikle devamı gelmesi gerektiği hakkında. Ama bir türlü zaman bulup devamını getiremedim. En nihayetinde bugun <strong>Hibernate ile Derinlemesine</strong> adlı bir yazı dizisine başlamış bulunmaktayım <img src='http://www.kamilors.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Bu yazıda ( Yazı-1), Hibernate&#8217;e Giriş yazısında anlattığım xml dosyaları ile yapılan eşleştirme işlemi yerine daha basit bir şekilde aynı işlemleri yapan ama bizi xml dosyalarından kurtaran Hibernate Annotation&#8217;ı anlatacağım. Annotation &#8216;ı türkçe karşılığı dipnot olarak çevirebiliriz. Annotation Java&#8217;nın bize sağladığı süper bir araç. Annotation&#8217;lar sınıfımızdaki elamanlara @ işareti ile eklediğimiz bazı fonksiyonlar ve parametrelerinden oluşur. Bu tanımlamalar derleme anında derleyici tarafından yorumlanırlar.<span id="more-97"></span></p>
<p>Yazıyı gecen sefer netbeans üzerinden anlatmıştım , Bu seferde aynı şekilde netbeans&#8217;den devam edeceğim.</p>
<p>Hibernate&#8217;in web (<a href="www.hibernate.org">www.hibernate.org</a>) adresinden <a href="https://www.hibernate.org/6.html">download</a> bölümünden <strong>Hibernate Core</strong> ve <strong>Hibernate Annotation</strong> adlı paketleri bilgisayarımıza indirelim. Ben Hibernate Core 3.3.2.GA ve Hibernate Annotation 3.4.0.GA versiyonlarını indirdim.</p>
<p>Şimdi bu indirdiğimiz iki sıkıştırılmış dosyayı açtıktan sonra içlerinden bize gerekli olan jar dosyalarını ortak bir klasörde toplayalım. hibernate-distribution-3.3.2.GA içinden bize gerekli olan jar dosyaları şunlardır.</p>
<ul>
<li>hibernate3.jar</li>
<li>lib/required/antlr-2.7.6.jar</li>
<li>lib/required/commons-collections-3.1.jar</li>
<li>lib/required/dom4j-1.6.1.jar</li>
<li>lib/required/javassist-3.9.0.GA.jar</li>
<li>lib/required/jta-1.1.jar</li>
<li>lib/required/slf4j-api-1.5.8.jar</li>
</ul>
<p>Yukarıdaki bu dosyaları ben masaüstümde hibernateLibs adında bir klasör oluşturarak bu klasörün içine kopyalayalım. Sonrasında Annotation için gerekli olan jar dosyalarını bu klasöre kopyalayalım. Bu dosyaslar ise ;</p>
<ul>
<li>hibernate-annotations.jar</li>
<li>lib/hibernate-comons-annotations.jar</li>
<li>lib/ejb3-persistence.jar</li>
<li>test/slf4j-log4j12.jar</li>
<li>test/log4j.jar</li>
</ul>
<p>Bu dosyalarıda hibernateLibs klasörüne kopyaladıktan sonra artık kuru fasülyenin faydalarına gelebiliriz <img src='http://www.kamilors.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<p><strong>Not: Yukarıdaki söylediğim jar dosyaları hibernate&#8217;in doğru çalışması için olan minumum gereksinim duyduğu kütüphanelerdir. Hibernate ile yapacağınız profesyonel projelerde hibernate,  bunlar haricinde 3. parti ekstra  kütüphanelere ihtiyaç duyabilir.</strong></p>
<p>Öncelikle Netbeans&#8217;ı açıyoruz tabi. Sonrasında File-&gt;New Project menüsünden çıkan pencerede Java-&gt; Java Application seçerekten en saf hali ile yeni bir java projesi oluşturuyoruz. Ben projenin adını <strong>tirtil</strong> koydum <img src='http://www.kamilors.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />   Projenin ana paket yolu ise  <strong>com.vizyon.arge.tirtil </strong>şeklinde. Bir ekran görüntüsü (ki ekran görüntüleri konuyu çok daha anlaşılır şekle getirmekte) vermek gerekirse görüntümüz saf haliyle böyle (Resim 1):</p>
<p style="text-align: center;"><a href="http://www.kamilors.com/files/yazilar/hibernate_derinlemesine_1_1.png"><img class="aligncenter" title="Resim 1" src="http://www.kamilors.com/files/yazilar/hibernate_derinlemesine_1_1.png" alt="" width="400" /></a></p>
<p style="text-align: left;">
<p style="text-align: left;">Şimdi projemize hibernate için gerekli olan kütüphaneleri dahil edelim. Bunun için sol kısımdaki proje ağacındaki <strong>Libraries&#8217;</strong>e sağ tıklayıp <strong>Add JAR/Folder&#8230; </strong>seçeneğini seçiyoruz. Karşımıza çıkan pencerede HibernateLibs klasörüne attığımız tüm jar dosyalarını ctrl yardımı ile hepsini seçiyoruz. Sonrasında Ok diyerek jar dosyalarının projemize dahil olmasını sağlıyoruz. bkz Resim 2</p>
<p style="text-align: left;">
<p style="text-align: center;"><a href="http://www.kamilors.com/files/yazilar/hibernate_derinlemesine_1_2.png"><img class="aligncenter" title="Resim 2" src="http://www.kamilors.com/files/yazilar/hibernate_derinlemesine_1_2.png" alt="" width="400" /></a></p>
<p style="text-align: left;">
<p style="text-align: left;">Hibernate ile ilgili kütüphanelerimizi ekledikten sonra mysql bağlantısını sağlayacak olan jdbc mysql connector jar&#8217;ınıda projemize ekliyoruz. Mysql jar&#8217;ınıda projemize ekledikten sonra kütüphane ekleme işlemi bitmiş oluyor.  Sıra projemize hibernate.cfg.xml dosyamızı ekleme geldi. Bu konuyu Hibernate&#8217;e Giriş bölümünde anlattığım için es geçiyorum.</p>
<p style="text-align: left;">
<p style="text-align: left;">
<p style="text-align: left;">Hibernate.cfg.xml dosyamızıda ekledikten sonra şimdi sıra HibernateUtil sınıfımızı oluşturmaya geldi. Hibernate Annotation kullanırken Util sınıfımızda bazı değişiklikler yapacağız.  Annotation kullanmadan önceki Util sınıfımız şu şekildeydi.</p>
<p style="text-align: left;">

<div class="wp_codebox"><table><tr id="p978"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
</pre></td><td class="code" id="p97code8"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> HibernateUtil <span style="color: #009900;">&#123;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> SessionFactory sessionFactory<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">static</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
sessionFactory <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Configuration<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">configure</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">buildSessionFactory</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">catch</span><span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Athrowable+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Throwable</span></a> ex<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aexceptionininitializererror+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">ExceptionInInitializerError</span></a><span style="color: #009900;">&#40;</span>ex<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> SessionFactory getSessionFactory<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000000; font-weight: bold;">return</span> sessionFactory<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p style="text-align: left;">
<p style="text-align: left;">Annotation kullanacağımız için Util dosyamıza annotation kullandığımızı belirtemiz gerek. Hibernate de ona göre davranarak Entity sınıflarımızı xml yada annotation&#8217;lara göre bulacaktır.</p>
<p style="text-align: left;">

<div class="wp_codebox"><table><tr id="p979"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
</pre></td><td class="code" id="p97code9"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> HibernateUtil <span style="color: #009900;">&#123;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> SessionFactory sessionFactory<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">static</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
sessionFactory <span style="color: #339933;">=</span>  <span style="color: #000000; font-weight: bold;">new</span> AnnotationConfiguration<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">configure</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">buildSessionFactory</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">catch</span><span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Athrowable+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Throwable</span></a> ex<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aexceptionininitializererror+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">ExceptionInInitializerError</span></a><span style="color: #009900;">&#40;</span>ex<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> SessionFactory getSessionFactory<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000000; font-weight: bold;">return</span> sessionFactory<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p style="text-align: left;">Yeni HibernateUtil.java sınıfımız bu şekilde. Aradaki tek fark configurasyonun annotation kullanarak yapıldığını belirtemek <img src='http://www.kamilors.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  Bütün buraya kadar başarılı bir şekilde gelip gelmediğimizi görmek için projemize sağ tıklayıp <strong>Clean And Build </strong>seçeneğini tıkyın. Ben tıkladığımda console&#8217;da <strong>BUILD SUCCESSFUL (total time: 0 seconds) </strong>şeklinde bir mesaj aldım. Yani bu zamana kadar her hangi eksik bişey yapmamışız.  Artık Entity sınıflarımızı oluşturmaya rahatlıkla geçebilriz <img src='http://www.kamilors.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p style="text-align: left;">Entity sınıflarını ayrı bir paket altında tutmamız her zaman daha iyidir. Onun için öncelikle<strong> com.vizyon.arge.tirtil.entity</strong> şeklinde yeni bir paket oluşturuyorum.  Şimdi entity sınıflarını oluşturacağız. Ben tirtil da basit şekilde uye bilgilerini tutan bir örnek ile devam edeceğim. Bundan sonraki yazılarda da bu ornek nesnelerde devam ederiz.</p>
<p style="text-align: left;">Öncelikle Uye.java sınıfımızı oluşturalım.</p>
<p style="text-align: left;">

<div class="wp_codebox"><table><tr id="p9710"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code" id="p97code10"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Uye <span style="color: #009900;">&#123;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">int</span> id<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">private</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> uyeAdi<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">private</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> sifre<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">private</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> mail<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">private</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> adi<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">private</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> soyadi<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">private</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> web<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p style="text-align: left;">şimdilik sadece bu bilgiler bize lazım olsun. İlerleyen yazılarda faha Uye.java sınıfımıza bir çok özellik ekleyeceğiz. Bu özellikleri ekledikten sonra hepsine birer getter ve setter eklememiz lazım. Tabi bunu el ile amelece (notpad kullananlar) yazmak yerine hızlı bir şekilde netbeans editörüne sağ tıklayıp Insert Code Seçeneğini seçiyoruz. Açılan küçük pencerede Getter And Setter seçeneği var. Onu seçerekten hızlı bir şekilde getter ve setter fonksiyonlarımızı oluşturuyoruz.</p>

<div class="wp_codebox"><table><tr id="p9711"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
</pre></td><td class="code" id="p97code11"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.vizyon.arge.tirtil.entity</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
*
* @author kamil
*/</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Uye <span style="color: #009900;">&#123;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">int</span> id<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">private</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> uyeAdi<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">private</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> sifre<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">private</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> mail<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">private</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> adi<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">private</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> soyadi<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">private</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> web<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">int</span> getId<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000000; font-weight: bold;">return</span> id<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setId<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> id<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">id</span> <span style="color: #339933;">=</span> id<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> getAdi<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000000; font-weight: bold;">return</span> adi<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setAdi<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> adi<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">adi</span> <span style="color: #339933;">=</span> adi<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> getMail<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000000; font-weight: bold;">return</span> mail<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setMail<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> mail<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">mail</span> <span style="color: #339933;">=</span> mail<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> getSifre<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000000; font-weight: bold;">return</span> sifre<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setSifre<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> sifre<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">sifre</span> <span style="color: #339933;">=</span> sifre<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> getSoyadi<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000000; font-weight: bold;">return</span> soyadi<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setSoyadi<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> soyadi<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">soyadi</span> <span style="color: #339933;">=</span> soyadi<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> getUyeAdi<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000000; font-weight: bold;">return</span> uyeAdi<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setUyeAdi<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> uyeAdi<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">uyeAdi</span> <span style="color: #339933;">=</span> uyeAdi<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> getWeb<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000000; font-weight: bold;">return</span> web<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setWeb<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> web<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">web</span> <span style="color: #339933;">=</span> web<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Buraya kadar bir solukta geldik. Şimdi sıra, daha önce xml dosyalarımız ile yaptığımız veritabanı ile entity nesnemiz arasındaki eşleştirmeyi , annotation&#8217;ları kullanarak yapmaya.  Basit olarak bir kaç tane annotation&#8217;nın ne işe yaradığını öncelikle açıklayayım. Daha sonrasnda bu annodation&#8217;ları sınıfımız üzerinde doğru yerlere serpiştiririz.</p>
<ul>
<li><strong>@Entity</strong> : Sınıf tanımlamasının hemen bir üst satırına yazılır. O sınıfın bir entity sınıfı olduğunu belirtir. paket adresi <strong>javax.persistence.Entity;</strong></li>
<li><strong>@Table </strong>: Sınıf tanımlamasının hemen bir üst satırına yazılır. O sınıfın hangi tablo ile eşleştiğini bildirir.  <strong>name</strong> parametresi ile tablo adı belirtilir.  paket adresi <strong>javax.persistence.Table;</strong></li>
<li><strong>@Id</strong> : Tablodaki birincil ahantar olarak karşılığı  bulunan sınıf değişkeninin getter fonksiyonunun hemen bir üst satırına yazılır.  paket adresi <strong>javax.persistence.Id</strong>;</li>
<li><strong>GeneratedValue</strong> : Birincil ahantarın otomatik değer alma biçimini belirtir. mysql&#8217;deki auto_incrament&#8217;in karşılığıda diyebiliriz.  oluşturma tipi <strong>strategy</strong> parametresi ile belirtilir.  <strong>IDENTITY, SEQUENCE, TABLE, AUTO </strong>şeklinde 4 parametre alır. Mysql kullanacaklar <strong>IDENTITY</strong> seçmelidir. paket adresi <strong>javax.persistence.GeneratedValue;</strong></li>
<li><strong>@Column</strong> : tablodaki alan ismini simgeler. <strong>name</strong> ile alan adı parametre olarak gönderilir. nullable parametresi ile boş bırakılabilir alan olup olamayacağı, length ile ise alanın büyüklüğü belirtilir. String türündeki bir değişken için <strong>@Column(name=&#8221;adi&#8221; , nullable = false, length = 25)</strong> şeklindeki bir tanımlama adi <strong>VARCHAR(25) NotNull</strong> &#8216;a karşılık gelir.  Parametrelerin default değerleri vardır. Eğerki parametreyi tanımlamada kullanmazsanız default değerini alır. Örn: nullable parametresinin default olarak değeri true &#8216;dur.</li>
</ul>
<p>Evet şimdilik buradaki tanıttığım annodationları Uye sınıfımıza serpiştirelim.</p>

<div class="wp_codebox"><table><tr id="p9712"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
</pre></td><td class="code" id="p97code12"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.vizyon.arge.tirtil.entity</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.persistence.Column</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.persistence.Entity</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.persistence.GeneratedValue</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.persistence.GenerationType</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.persistence.Id</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.persistence.Table</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
*
* @author kamil
*/</span>
&nbsp;
@<a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aentity+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Entity</span></a>
@Table<span style="color: #009900;">&#40;</span>name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Uye&quot;</span>, catalog<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;tirtil&quot;</span><span style="color: #009900;">&#41;</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Uye <span style="color: #009900;">&#123;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">int</span> id<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">private</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> uyeAdi<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">private</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> sifre<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">private</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> mail<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">private</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> adi<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">private</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> soyadi<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">private</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> web<span style="color: #339933;">;</span>
&nbsp;
@Id
@GeneratedValue<span style="color: #009900;">&#40;</span>strategy<span style="color: #339933;">=</span>GenerationType.<span style="color: #006633;">IDENTITY</span><span style="color: #009900;">&#41;</span>
@Column<span style="color: #009900;">&#40;</span>name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;id&quot;</span>, nullable<span style="color: #339933;">=</span><span style="color: #000066; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">int</span> getId<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000000; font-weight: bold;">return</span> id<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setId<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> id<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">id</span> <span style="color: #339933;">=</span> id<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
@Column<span style="color: #009900;">&#40;</span>name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;adi&quot;</span>, nullable<span style="color: #339933;">=</span><span style="color: #000066; font-weight: bold;">false</span> , length<span style="color: #339933;">=</span> <span style="color: #cc66cc;">30</span><span style="color: #009900;">&#41;</span>
<span style="color: #000000; font-weight: bold;">public</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> getAdi<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000000; font-weight: bold;">return</span> adi<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setAdi<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> adi<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">adi</span> <span style="color: #339933;">=</span> adi<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
@Column<span style="color: #009900;">&#40;</span>name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;e_mail&quot;</span>, nullable<span style="color: #339933;">=</span><span style="color: #000066; font-weight: bold;">false</span>, length<span style="color: #339933;">=</span> <span style="color: #cc66cc;">100</span><span style="color: #009900;">&#41;</span>
<span style="color: #000000; font-weight: bold;">public</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> getMail<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000000; font-weight: bold;">return</span> mail<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setMail<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> mail<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">mail</span> <span style="color: #339933;">=</span> mail<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
@Column<span style="color: #009900;">&#40;</span>name<span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;sifre&quot;</span>, nullable<span style="color: #339933;">=</span><span style="color: #000066; font-weight: bold;">false</span>,length<span style="color: #339933;">=</span><span style="color: #cc66cc;">128</span><span style="color: #009900;">&#41;</span>
<span style="color: #000000; font-weight: bold;">public</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> getSifre<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000000; font-weight: bold;">return</span> sifre<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setSifre<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> sifre<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">sifre</span> <span style="color: #339933;">=</span> sifre<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
@Column<span style="color: #009900;">&#40;</span>name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;soyadi&quot;</span>, length<span style="color: #339933;">=</span> <span style="color: #cc66cc;">30</span><span style="color: #009900;">&#41;</span>
<span style="color: #000000; font-weight: bold;">public</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> getSoyadi<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000000; font-weight: bold;">return</span> soyadi<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setSoyadi<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> soyadi<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">soyadi</span> <span style="color: #339933;">=</span> soyadi<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
@Column<span style="color: #009900;">&#40;</span>name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;uye_adi&quot;</span>, length<span style="color: #339933;">=</span><span style="color: #cc66cc;">50</span><span style="color: #009900;">&#41;</span>
<span style="color: #000000; font-weight: bold;">public</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> getUyeAdi<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000000; font-weight: bold;">return</span> uyeAdi<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setUyeAdi<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> uyeAdi<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">uyeAdi</span> <span style="color: #339933;">=</span> uyeAdi<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
@Column<span style="color: #009900;">&#40;</span>name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;url&quot;</span><span style="color: #009900;">&#41;</span>
<span style="color: #000000; font-weight: bold;">public</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> getWeb<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000000; font-weight: bold;">return</span> web<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setWeb<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> web<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">web</span> <span style="color: #339933;">=</span> web<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Böylelikle tanımlamalarımızıda bitirmiş oluyoruz <img src='http://www.kamilors.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  Şimdi bu sınıfımızı HibernateUtil.java sınıfında AnnotatedClass olarak tanımlamalıyız. Bunu işlem xml ile yapılandırma yapar iken hbm dosyalarımızı hibernate.cfg.xml dosyasına eklediğimiz mantık ile aynı.</p>

<div class="wp_codebox"><table><tr id="p9713"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
</pre></td><td class="code" id="p97code13"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.vizyon.arge.tirtil.util</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.hibernate.SessionFactory</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.hibernate.cfg.AnnotationConfiguration</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
*
* @author kamil
*/</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> HibernateUtil <span style="color: #009900;">&#123;</span>
<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> SessionFactory sessionFactory<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">static</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
sessionFactory <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> AnnotationConfiguration<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
.<span style="color: #006633;">addPackage</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;com.vizyon.arge.tirtil.entity&quot;</span><span style="color: #009900;">&#41;</span>
.<span style="color: #006633;">addAnnotatedClass</span><span style="color: #009900;">&#40;</span>com.<span style="color: #006633;">vizyon</span>.<span style="color: #006633;">arge</span>.<span style="color: #006633;">tirtil</span>.<span style="color: #006633;">entity</span>.<span style="color: #006633;">Uye</span>.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span>
.<span style="color: #006633;">configure</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">buildSessionFactory</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">catch</span><span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Athrowable+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Throwable</span></a> ex<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aexceptionininitializererror+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">ExceptionInInitializerError</span></a><span style="color: #009900;">&#40;</span>ex<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> SessionFactory getSessionFactory<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000000; font-weight: bold;">return</span> sessionFactory<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Buraya kadar herşeyi tamamladık. Şimdi projemizi bir test edelim. <strong>Hibernate&#8217;e Giriş</strong> yazısından hatırlayacağınız gibi hibernate.cfg.xml dosyasındaki bir özellik ile projemiz başlatılır iken otomatik olarak sınıflardaki değişiklikleri veritabanına yansıtabilmesini sağlayabililiyorduk.</p>
<p><strong>&lt;property name=&#8221;hbm2ddl.auto&#8221;&gt;update&lt;/property&gt;</strong></p>
<p>hbm2ddl.auto = update olduğu için projemizi ilk başlattığımızda bizim için uye tablosu otomatik olarak veritabanında oluşturulması lazım. Onun için şimdi Main.java sınıfına şu kod parçacığını yararak projemizi çalıştıralım.</p>

<div class="wp_codebox"><table><tr id="p9714"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
</pre></td><td class="code" id="p97code14"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Main <span style="color: #009900;">&#123;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
* @param args the command line arguments
*/</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> args<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
Session session <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
session <span style="color: #339933;">=</span> HibernateUtil.<span style="color: #006633;">getSessionFactory</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">openSession</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Welcome Tirtil!&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">catch</span><span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Exception</span></a> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>e.<span style="color: #006633;">getMessage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">finally</span> <span style="color: #009900;">&#123;</span>
session.<span style="color: #006633;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Projeyi çalıştırdığımda Console&#8217;da <strong>Welcome Tirtil!</strong> yazısını aldım. Bu sonuç bize  bütün işlemleri tamamladığımızı gösteriyor. Veritabanında uye tablosu başarılı bir şekilde oluşturulmuş:</p>
<p style="text-align: center;"><a href="http://www.kamilors.com/files/yazilar/hibernate_derinlemesine_1_5.png"><img class="aligncenter" title="Resim 5" src="http://www.kamilors.com/files/yazilar/hibernate_derinlemesine_1_5.png" alt="" width="400" /></a></p>
<p>Bir sonraki yazıda annotation ile yapılandırmalara devam edeceğim. Sınıflar arası ilişkileri annotation ile nasıl tanımlayacağımızı göstereceğim. Daha sonrasında ise Session yönetimi, insert, delete gibi işlemlerin hibernate ile nasıl yapıldığını göstereceğim.</p>
<p>Şimdilik bukadar <img src='http://www.kamilors.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<div id="_mcePaste" style="overflow: hidden; position: absolute; left: -10000px; top: 335px; width: 1px; height: 1px;">http://www.kamilors.com/files/yazilar/hibernate_derinlemesine_1_1.png</div>
]]></content:encoded>
			<wfw:commentRss>http://www.kamilors.com/hibernate-ile-derinlemesine-1-annotations/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

