title: org.hibernate.LazyInitializationException: could not initialize proxy - no Session | DAO
body: <p>I searched for this problem too much, but I couldn't solve. I'm getting <code>org.hibernate.LazyInitializationException: could not initialize proxy - no Session</code>
  exception, even though I tried to initialize firma.getSektor(). 
  I couldn't see any relationship or annotation problem in Sektor.java or Firma.java.
  Please help me. </p>
  
  <p><strong>Edit:</strong> I don't have a positive look on using Eagle Loading to solve this problem because of it might decrease peformance.</p>
  
  <p>Exception:</p>
  
  <pre><code>Caused by: org.hibernate.LazyInitializationException: could not initialize proxy - no Session
  at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:167)
  at org.hibernate.Hibernate.initialize(Hibernate.java:414)
  at CRMFunctions.CRMFunctions.TableDoldur(CRMFunctions.java:804)
  at app.FirmaYonetim.Firmalar.&lt;init&gt;(Firmalar.java:138)
  ... 43 more
  </code></pre>
  
  <p>My Code:</p>
  
  <pre><code>public static ApplicationContext context = new ClassPathXmlApplicationContext("application.xml");
  public static FirmaHome FIRMA_HOME = (FirmaHome) context.getBean("firmaHome");
  
  
  Vector&lt;Vector&lt;?&gt;&gt; firmaData = new Vector&lt;Vector&lt;?&gt;&gt;();
          List&lt;Firma&gt; firmas = FIRMA_HOME.findAll();
          if (firmas.size() &gt; 0) {
              for (Firma firma : firmas) {
                  Vector vector = new Vector();
                  vector.add(firma.getFirmaId());
                  vector.add(firma.getFirmaUnvan());
                  vector.add(firma.getFirmaVergiDairesi());
                  vector.add(firma.getFirmaVergiNo());
                  Hibernate.initialize(firma.getSektor());
                  vector.add(firma.getSektor().getSektorAd());
                  firmaData.add(vector);
              }   
          }               
          return new CRMTable(firmaData, Arrays.asList("Firma ID", "Unvan", "Vergi Dairesi", "Vergi No" ,"Sektor"), 1, new Boolean[] { false, false,
              false, false, false });
  </code></pre>
  
  <p>application.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
      xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
      xsi:schemaLocation="
             http://www.springframework.org/schema/beans
             http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
             http://www.springframework.org/schema/tx 
             http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
             http://www.springframework.org/schema/aop
             http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
             http://www.springframework.org/schema/context
             http://www.springframework.org/schema/context/spring-context-3.0.xsd"&gt;
  
  &lt;bean id="ilHome" class="dto.IlHome"&gt;
      &lt;property name="hibernateTemplate" ref="hibernateTemplate" /&gt;
  &lt;/bean&gt;
  
  &lt;bean id="anlasmaHome" class="dto.AnlasmaHome"&gt;
      &lt;property name="hibernateTemplate" ref="hibernateTemplate" /&gt;
  &lt;/bean&gt;
  
  &lt;bean id="bankaHome" class="dto.BankaHome"&gt;
      &lt;property name="hibernateTemplate" ref="hibernateTemplate" /&gt;
  &lt;/bean&gt;
  
  &lt;bean id="depoUrunHome" class="dto.DepoUrunHome"&gt;
      &lt;property name="hibernateTemplate" ref="hibernateTemplate" /&gt;
  &lt;/bean&gt;
  
  &lt;bean id="duyuruHome" class="dto.DuyuruHome"&gt;
      &lt;property name="hibernateTemplate" ref="hibernateTemplate" /&gt;
  &lt;/bean&gt;
  
  &lt;bean id="duyuruAliciHome" class="dto.DuyuruAliciHome"&gt;
      &lt;property name="hibernateTemplate" ref="hibernateTemplate" /&gt;
  &lt;/bean&gt;
  
  &lt;bean id="firmaHome" class="dto.FirmaHome"&gt;
      &lt;property name="hibernateTemplate" ref="hibernateTemplate" /&gt;
  &lt;/bean&gt;
  
  &lt;bean id="gonderiHome" class="dto.GonderiHome"&gt;
      &lt;property name="hibernateTemplate" ref="hibernateTemplate" /&gt;
  &lt;/bean&gt;
  
  &lt;bean id="gonderiDurumHome" class="dto.GonderiDurumHome"&gt;
      &lt;property name="hibernateTemplate" ref="hibernateTemplate" /&gt;
  &lt;/bean&gt;
  
  &lt;bean id="hastalikRaporHome" class="dto.HastalikRaporHome"&gt;
      &lt;property name="hibernateTemplate" ref="hibernateTemplate" /&gt;
  &lt;/bean&gt;
  
  &lt;bean id="ilceHome" class="dto.IlceHome"&gt;
      &lt;property name="hibernateTemplate" ref="hibernateTemplate" /&gt;
  &lt;/bean&gt;
  
  &lt;bean id="kampanyaHome" class="dto.KampanyaHome"&gt;
      &lt;property name="hibernateTemplate" ref="hibernateTemplate" /&gt;
  &lt;/bean&gt;
  
  &lt;bean id="kaynakHome" class="dto.KaynakHome"&gt;
      &lt;property name="hibernateTemplate" ref="hibernateTemplate" /&gt;
  &lt;/bean&gt;
  
  &lt;bean id="mahalleHome" class="dto.MahalleHome"&gt;
      &lt;property name="hibernateTemplate" ref="hibernateTemplate" /&gt;
  &lt;/bean&gt;
  
  &lt;bean id="markaHome" class="dto.MarkaHome"&gt;
      &lt;property name="hibernateTemplate" ref="hibernateTemplate" /&gt;
  &lt;/bean&gt;
  
  &lt;bean id="meslekHome" class="dto.MeslekHome"&gt;
      &lt;property name="hibernateTemplate" ref="hibernateTemplate" /&gt;
  &lt;/bean&gt;
  
  &lt;bean id="musteriHome" class="dto.MusteriHome"&gt;
      &lt;property name="hibernateTemplate" ref="hibernateTemplate" /&gt;
  &lt;/bean&gt;
  
  &lt;bean id="musteriAdresHome" class="dto.MusteriAdresHome"&gt;
      &lt;property name="hibernateTemplate" ref="hibernateTemplate" /&gt;
  &lt;/bean&gt;
  
  &lt;bean id="musteriKaraListeHome" class="dto.MusteriKaraListeHome"&gt;
      &lt;property name="hibernateTemplate" ref="hibernateTemplate" /&gt;
  &lt;/bean&gt;
  
  &lt;bean id="musteriMailHome" class="dto.MusteriMailHome"&gt;
      &lt;property name="hibernateTemplate" ref="hibernateTemplate" /&gt;
  &lt;/bean&gt;
  
  &lt;bean id="musteriTelefonHome" class="dto.MusteriTelefonHome"&gt;
      &lt;property name="hibernateTemplate" ref="hibernateTemplate" /&gt;
  &lt;/bean&gt;
  
  &lt;bean id="musteriWebHome" class="dto.MusteriWebHome"&gt;
      &lt;property name="hibernateTemplate" ref="hibernateTemplate" /&gt;
  &lt;/bean&gt;
  
  &lt;bean id="musteriNotHome" class="dto.MusteriNotHome"&gt;
      &lt;property name="hibernateTemplate" ref="hibernateTemplate" /&gt;
  &lt;/bean&gt;
  
  &lt;bean id="musteriSikayetHome" class="dto.MusteriSikayetHome"&gt;
      &lt;property name="hibernateTemplate" ref="hibernateTemplate" /&gt;
  &lt;/bean&gt;
  
  &lt;bean id="musteriTakipHome" class="dto.MusteriTakipHome"&gt;
      &lt;property name="hibernateTemplate" ref="hibernateTemplate" /&gt;
  &lt;/bean&gt;
  
  &lt;bean id="personelHome" class="dto.PersonelHome"&gt;
      &lt;property name="hibernateTemplate" ref="hibernateTemplate" /&gt;
  &lt;/bean&gt;
  
  &lt;bean id="personelAdresHome" class="dto.PersonelAdresHome"&gt;
      &lt;property name="hibernateTemplate" ref="hibernateTemplate" /&gt;
  &lt;/bean&gt;
  
  &lt;bean id="personelBankaHesapHome" class="dto.PersonelBankaHesapHome"&gt;
      &lt;property name="hibernateTemplate" ref="hibernateTemplate" /&gt;
  &lt;/bean&gt;
  
  &lt;bean id="personelEskiFirmaHome" class="dto.PersonelEskiFirmaHome"&gt;
      &lt;property name="hibernateTemplate" ref="hibernateTemplate" /&gt;
  &lt;/bean&gt;
  
  &lt;bean id="personelHastalikHome" class="dto.PersonelHastalikHome"&gt;
      &lt;property name="hibernateTemplate" ref="hibernateTemplate" /&gt;
  &lt;/bean&gt;
  
  &lt;bean id="personelIzinHome" class="dto.PersonelIzinHome"&gt;
      &lt;property name="hibernateTemplate" ref="hibernateTemplate" /&gt;
  &lt;/bean&gt;
  
  &lt;bean id="personelKaraListeHome" class="dto.PersonelKaraListeHome"&gt;
      &lt;property name="hibernateTemplate" ref="hibernateTemplate" /&gt;
  &lt;/bean&gt;
  
  &lt;bean id="personelMailHome" class="dto.PersonelMailHome"&gt;
      &lt;property name="hibernateTemplate" ref="hibernateTemplate" /&gt;
  &lt;/bean&gt;
  
  &lt;bean id="personelTelefonHome" class="dto.PersonelTelefonHome"&gt;
      &lt;property name="hibernateTemplate" ref="hibernateTemplate" /&gt;
  &lt;/bean&gt;
  
  &lt;bean id="PersonelSozlesmeHome" class="dto.PersonelSozlesmeHome"&gt;
      &lt;property name="hibernateTemplate" ref="hibernateTemplate" /&gt;
  &lt;/bean&gt;
  
  &lt;bean id="personelWebHome" class="dto.PersonelWebHome"&gt;
      &lt;property name="hibernateTemplate" ref="hibernateTemplate" /&gt;
  &lt;/bean&gt;
  
  &lt;bean id="personelYoklamaHome" class="dto.PersonelYoklamaHome"&gt;
      &lt;property name="hibernateTemplate" ref="hibernateTemplate" /&gt;
  &lt;/bean&gt;
  
  &lt;bean id="postaKoduHome" class="dto.PostaKoduHome"&gt;
      &lt;property name="hibernateTemplate" ref="hibernateTemplate" /&gt;
  &lt;/bean&gt;
  
  &lt;bean id="satisHome" class="dto.SatisHome"&gt;
      &lt;property name="hibernateTemplate" ref="hibernateTemplate" /&gt;
  &lt;/bean&gt;
  
  &lt;bean id="sektorHome" class="dto.SektorHome"&gt;
      &lt;property name="hibernateTemplate" ref="hibernateTemplate" /&gt;
  &lt;/bean&gt;
  
  &lt;bean id="semtHome" class="dto.SemtHome"&gt;
      &lt;property name="hibernateTemplate" ref="hibernateTemplate" /&gt;
  &lt;/bean&gt;
  
  &lt;bean id="subeHome" class="dto.SubeHome"&gt;
      &lt;property name="hibernateTemplate" ref="hibernateTemplate" /&gt;
  &lt;/bean&gt;
  
  &lt;bean id="subeAdresHome" class="dto.SubeAdresHome"&gt;
      &lt;property name="hibernateTemplate" ref="hibernateTemplate" /&gt;
  &lt;/bean&gt;
  
  &lt;bean id="subeMailHome" class="dto.SubeMailHome"&gt;
      &lt;property name="hibernateTemplate" ref="hibernateTemplate" /&gt;
  &lt;/bean&gt;
  
  &lt;bean id="subeTelefonHome" class="dto.SubeTelefonHome"&gt;
      &lt;property name="hibernateTemplate" ref="hibernateTemplate" /&gt;
  &lt;/bean&gt;
  
  &lt;bean id="subeWebHome" class="dto.SubeWebHome"&gt;
      &lt;property name="hibernateTemplate" ref="hibernateTemplate" /&gt;
  &lt;/bean&gt;
  
  
  &lt;bean id="ulkeHome" class="dto.UlkeHome"&gt;
      &lt;property name="hibernateTemplate" ref="hibernateTemplate" /&gt;
  &lt;/bean&gt;
  
  
  &lt;bean id="urunHome" class="dto.UrunHome"&gt;
      &lt;property name="hibernateTemplate" ref="hibernateTemplate" /&gt;
  &lt;/bean&gt;
  
  &lt;bean id="urunBarkodHome" class="dto.UrunBarkodHome"&gt;
      &lt;property name="hibernateTemplate" ref="hibernateTemplate" /&gt;
  &lt;/bean&gt;
  
  &lt;bean id="urunGrupHome" class="dto.UrunGrupHome"&gt;
      &lt;property name="hibernateTemplate" ref="hibernateTemplate" /&gt;
  &lt;/bean&gt;
  
  &lt;bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate"&gt;
      &lt;property name="sessionFactory" ref="sessionFactory" /&gt;
  &lt;/bean&gt;
  
  &lt;bean id="sessionFactory"
      class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"&gt;
      &lt;property name="configLocation"&gt;
          &lt;value&gt;hibernate.cfg.xml&lt;/value&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  
  &lt;aop:config&gt;
      &lt;aop:pointcut id="serviceOperation" expression="execution(* dto..*Home.*(..))" /&gt;
      &lt;aop:advisor pointcut-ref="serviceOperation" advice-ref="txAdvice" /&gt;
  &lt;/aop:config&gt;
  
  &lt;tx:advice id="txAdvice"&gt;
      &lt;tx:attributes&gt;
          &lt;tx:method name="get*" read-only="true" /&gt;
          &lt;tx:method name="*" /&gt;
      &lt;/tx:attributes&gt;
  &lt;/tx:advice&gt;
  &lt;!-- enable the configuration of transactional behavior based on annotations 
  &lt;tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true" /&gt;--&gt;
  
  &lt;bean id="transactionManager"
      class="org.springframework.orm.hibernate3.HibernateTransactionManager"&gt;
      &lt;property name="sessionFactory" ref="sessionFactory" /&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>      </p>
  
  <p>hibernate.cfg.xml</p>
  
  <pre><code>&lt;hibernate-configuration&gt;
  &lt;session-factory&gt;
      &lt;property name="hibernate.bytecode.use_reflection_optimizer"&gt;false&lt;/property&gt;
      &lt;property name="hibernate.cache.provider_class"&gt;org.hibernate.cache.NoCacheProvider&lt;/property&gt;
      &lt;property name="hibernate.connection.characterEncoding"&gt;utf8&lt;/property&gt;
      &lt;property name="hibernate.connection.driver_class"&gt;com.mysql.jdbc.Driver&lt;/property&gt;
      &lt;property name="hibernate.connection.password"&gt;****&lt;/property&gt;
      &lt;property name="hibernate.connection.url"&gt;jdbc:mysql://192.168.1.110:3306/HalfaCrmDb&lt;/property&gt;
      &lt;property name="hibernate.connection.username"&gt;***&lt;/property&gt;
      &lt;property name="hibernate.current_session_context_class"&gt;thread&lt;/property&gt;
      &lt;property name="hibernate.dialect"&gt;org.hibernate.dialect.MySQL5InnoDBDialect&lt;/property&gt;
      &lt;property name="hibernate.search.autoregister_listeners"&gt;false&lt;/property&gt;
      &lt;property name="hibernate.show_sql"&gt;true&lt;/property&gt;          
      &lt;mapping class="dto.Urun" resource="dto/Urun.hbm.xml"/&gt;
      &lt;mapping class="dto.PersonelKaraListe" resource="dto/PersonelKaraListe.hbm.xml" /&gt;
      &lt;mapping class="dto.PersonelMail" resource="dto/PersonelMail.hbm.xml" /&gt;
      &lt;mapping class="dto.DuyuruAlici" resource="dto/DuyuruAlici.hbm.xml" /&gt;
      &lt;mapping class="dto.Musteri" resource="dto/Musteri.hbm.xml" /&gt;
      &lt;mapping class="dto.Semt" resource="dto/Semt.hbm.xml" /&gt;
      &lt;mapping class="dto.Ulke" resource="dto/Ulke.hbm.xml" /&gt;
      &lt;mapping class="dto.MusteriTakip" resource="dto/MusteriTakip.hbm.xml" /&gt;
      &lt;mapping class="dto.SubeMail" resource="dto/SubeMail.hbm.xml" /&gt;
      &lt;mapping class="dto.MusteriTelefon" resource="dto/MusteriTelefon.hbm.xml" /&gt;
      &lt;mapping class="dto.DepoUrun" resource="dto/DepoUrun.hbm.xml" /&gt;
      &lt;mapping class="dto.Il" resource="dto/Il.hbm.xml" /&gt;
      &lt;mapping class="dto.Kampanya" resource="dto/Kampanya.hbm.xml" /&gt;
      &lt;mapping class="dto.PersonelWeb" resource="dto/PersonelWeb.hbm.xml" /&gt;
      &lt;mapping class="dto.MusteriKaraListe" resource="dto/MusteriKaraListe.hbm.xml" /&gt;
      &lt;mapping class="dto.PostaKodu" resource="dto/PostaKodu.hbm.xml" /&gt;
      &lt;mapping class="dto.Marka" resource="dto/Marka.hbm.xml" /&gt;
      &lt;mapping class="dto.UrunGrup" resource="dto/UrunGrup.hbm.xml" /&gt;
      &lt;mapping class="dto.PersonelTelefon" resource="dto/PersonelTelefon.hbm.xml" /&gt;
      &lt;mapping class="dto.Mahalle" resource="dto/Mahalle.hbm.xml" /&gt;
      &lt;mapping class="dto.Duyuru" resource="dto/Duyuru.hbm.xml" /&gt;
      &lt;mapping class="dto.Firma" resource="dto/Firma.hbm.xml" /&gt;
      &lt;mapping class="dto.PersonelYoklama" resource="dto/PersonelYoklama.hbm.xml" /&gt;
      &lt;mapping class="dto.SatisUrun" resource="dto/SatisUrun.hbm.xml" /&gt;
      &lt;mapping class="dto.Kaynak" resource="dto/Kaynak.hbm.xml" /&gt;
      &lt;mapping class="dto.Anlasma" resource="dto/Anlasma.hbm.xml" /&gt;
      &lt;mapping class="dto.MusteriNot" resource="dto/MusteriNot.hbm.xml" /&gt;
      &lt;mapping class="dto.Ilce" resource="dto/Ilce.hbm.xml" /&gt;
      &lt;mapping class="dto.PersonelBankaHesap" resource="dto/PersonelBankaHesap.hbm.xml" /&gt;
      &lt;mapping class="dto.PersonelHastalik" resource="dto/PersonelHastalik.hbm.xml" /&gt;
      &lt;mapping class="dto.MusteriSikayet" resource="dto/MusteriSikayet.hbm.xml" /&gt;
      &lt;mapping class="dto.Gonderi" resource="dto/Gonderi.hbm.xml" /&gt;
      &lt;mapping class="dto.PersonelAdres" resource="dto/PersonelAdres.hbm.xml" /&gt;
      &lt;mapping class="dto.SubeTelefon" resource="dto/SubeTelefon.hbm.xml" /&gt;
      &lt;mapping class="dto.MusteriMail" resource="dto/MusteriMail.hbm.xml" /&gt;
      &lt;mapping class="dto.GonderiDurum" resource="dto/GonderiDurum.hbm.xml" /&gt;
      &lt;mapping class="dto.HastalikRapor" resource="dto/HastalikRapor.hbm.xml" /&gt;
      &lt;mapping class="dto.UrunBarkod" resource="dto/UrunBarkod.hbm.xml" /&gt;
      &lt;mapping class="dto.Meslek" resource="dto/Meslek.hbm.xml" /&gt;
      &lt;mapping class="dto.Personel" resource="dto/Personel.hbm.xml" /&gt;
      &lt;mapping class="dto.Sektor" resource="dto/Sektor.hbm.xml" /&gt;
      &lt;mapping class="dto.PersonelSozlesme" resource="dto/PersonelSozlesme.hbm.xml" /&gt;
      &lt;mapping class="dto.MusteriAdres" resource="dto/MusteriAdres.hbm.xml" /&gt;
      &lt;mapping class="dto.SubeAdres" resource="dto/SubeAdres.hbm.xml" /&gt;
      &lt;mapping class="dto.SubeWeb" resource="dto/SubeWeb.hbm.xml" /&gt;
      &lt;mapping class="dto.PersonelEskiFirma" resource="dto/PersonelEskiFirma.hbm.xml" /&gt;
      &lt;mapping class="dto.Satis" resource="dto/Satis.hbm.xml" /&gt;
      &lt;mapping class="dto.Banka" resource="dto/Banka.hbm.xml" /&gt;
      &lt;mapping class="dto.PersonelIzin" resource="dto/PersonelIzin.hbm.xml" /&gt;
      &lt;mapping class="dto.MusteriWeb" resource="dto/MusteriWeb.hbm.xml" /&gt;
      &lt;mapping class="dto.Sube" resource="dto/Sube.hbm.xml" /&gt;
  &lt;/session-factory&gt;
  </code></pre>
  
  <p></p>
  
  <p>Firma.hbm.xml</p>
  
  <pre><code>&lt;hibernate-mapping&gt;
      &lt;class name="dto.Firma" table="Firma" catalog="HalfaCrmDb"&gt;
          &lt;id name="firmaId" type="java.lang.Integer"&gt;
              &lt;column name="firmaId" /&gt;
              &lt;generator class="identity" /&gt;
          &lt;/id&gt;
          &lt;many-to-one name="sektor" class="dto.Sektor" fetch="select"&gt;
              &lt;column name="firmaSektorId"&gt;
                  &lt;comment&gt;Sektor TBL'den ID gelecek&lt;/comment&gt;
              &lt;/column&gt;
          &lt;/many-to-one&gt;
          &lt;property name="firmaUnvan" type="string"&gt;
              &lt;column name="firmaUnvan" /&gt;
          &lt;/property&gt;
          &lt;property name="firmaVergiDairesi" type="string"&gt;
              &lt;column name="firmaVergiDairesi" /&gt;
          &lt;/property&gt;
          &lt;property name="firmaVergiNo" type="string"&gt;
              &lt;column name="firmaVergiNo" length="11" /&gt;
          &lt;/property&gt;
          &lt;set name="subes" table="Sube" inverse="true" lazy="true" fetch="select"&gt;
              &lt;key&gt;
                  &lt;column name="subeFirmaId"&gt;
                      &lt;comment&gt;Firma TBL'den ID gelecek&lt;/comment&gt;
                  &lt;/column&gt;
              &lt;/key&gt;
              &lt;one-to-many class="dto.Sube" /&gt;
          &lt;/set&gt;
          &lt;set name="anlasmas" table="Anlasma" inverse="true" lazy="true" fetch="select"&gt;
              &lt;key&gt;
                  &lt;column name="anlasmaFirmaId"&gt;
                      &lt;comment&gt;Firma TBL'den ID gelecek&lt;/comment&gt;
                  &lt;/column&gt;
              &lt;/key&gt;
              &lt;one-to-many class="dto.Anlasma" /&gt;
          &lt;/set&gt;
          &lt;set name="markas" table="Marka" inverse="true" lazy="true" fetch="select"&gt;
              &lt;key&gt;
                  &lt;column name="markaFirmaId"&gt;
                      &lt;comment&gt;Firma TBL'den ID Gelecek&lt;/comment&gt;
                  &lt;/column&gt;
              &lt;/key&gt;
              &lt;one-to-many class="dto.Marka" /&gt;
          &lt;/set&gt;
      &lt;/class&gt;
  &lt;/hibernate-mapping&gt;
  </code></pre>
  
  <p>Sektor.hbm.xml</p>
  
  <pre><code>&lt;hibernate-mapping&gt;
  &lt;class name="dto.Sektor" table="Sektor" catalog="HalfaCrmDb"&gt;
      &lt;id name="sektorId" type="java.lang.Integer"&gt;
          &lt;column name="sektorId" /&gt;
          &lt;generator class="identity" /&gt;
      &lt;/id&gt;
      &lt;property name="sektorAd" type="string"&gt;
          &lt;column name="sektorAd" length="50" /&gt;
      &lt;/property&gt;
      &lt;set name="mesleks" table="Meslek" inverse="true" lazy="true" fetch="select"&gt;
          &lt;key&gt;
              &lt;column name="meslekSektorId"&gt;
                  &lt;comment&gt;Sektor TBL'den ID gelecek&lt;/comment&gt;
              &lt;/column&gt;
          &lt;/key&gt;
          &lt;one-to-many class="dto.Meslek" /&gt;
      &lt;/set&gt;
      &lt;set name="firmas" table="Firma" inverse="true" lazy="true" fetch="select"&gt;
          &lt;key&gt;
              &lt;column name="firmaSektorId"&gt;
                  &lt;comment&gt;Sektor TBL'den ID gelecek&lt;/comment&gt;
              &lt;/column&gt;
          &lt;/key&gt;
          &lt;one-to-many class="dto.Firma" /&gt;
      &lt;/set&gt;
  &lt;/class&gt;
  </code></pre>
  
  <p></p>
  
  <p>Sektor.java</p>
  
  <pre><code>@Entity
  @Table(name = "Sektor", catalog = "HalfaCrmDb")
  public class Sektor implements java.io.Serializable {
  
  private static final long serialVersionUID = 1370608783666448790L;
  private Integer sektorId;
  private String sektorAd;
  private Set&lt;Meslek&gt; mesleks = new HashSet&lt;Meslek&gt;(0);
  private Set&lt;Firma&gt; firmas = new HashSet&lt;Firma&gt;(0);
  
  public Sektor() {
  }
  
  public Sektor(String sektorAd, Set&lt;Meslek&gt; mesleks, Set&lt;Firma&gt; firmas) {
      this.sektorAd = sektorAd;
      this.mesleks = mesleks;
      this.firmas = firmas;
  }
  
  @Id
  @GeneratedValue(strategy = IDENTITY)
  @Column(name = "sektorId", unique = true, nullable = false)
  public Integer getSektorId() {
      return this.sektorId;
  }
  
  public void setSektorId(Integer sektorId) {
      this.sektorId = sektorId;
  }
  
  @Column(name = "sektorAd", length = 50)
  public String getSektorAd() {
      return this.sektorAd;
  }
  
  public void setSektorAd(String sektorAd) {
      this.sektorAd = sektorAd;
  }
  
  @OneToMany(fetch = FetchType.LAZY, mappedBy = "sektor")
  public Set&lt;Meslek&gt; getMesleks() {
      return this.mesleks;
  }
  
  public void setMesleks(Set&lt;Meslek&gt; mesleks) {
      this.mesleks = mesleks;
  }
  
  @OneToMany(fetch = FetchType.LAZY, mappedBy = "sektor")
  public Set&lt;Firma&gt; getFirmas() {
      return this.firmas;
  }
  
  public void setFirmas(Set&lt;Firma&gt; firmas) {
      this.firmas = firmas;
  }
  }
  </code></pre>
  
  <p>Firma.java</p>
  
  <pre><code>    @Entity
      @Table(name = "Firma", catalog = "HalfaCrmDb")
  public class Firma implements java.io.Serializable {        
      private static final long serialVersionUID = -4310046345444125265L;
      private Integer firmaId;
      private Sektor sektor;
      private String firmaUnvan;
      private String firmaVergiDairesi;
      private String firmaVergiNo;
      private Set&lt;Sube&gt; subes = new HashSet&lt;Sube&gt;(0);
      private Set&lt;Anlasma&gt; anlasmas = new HashSet&lt;Anlasma&gt;(0);
      private Set&lt;Marka&gt; markas = new HashSet&lt;Marka&gt;(0);
  
      public Firma() {
      }
  
      public Firma(Sektor sektor, String firmaUnvan, String firmaVergiDairesi,
              String firmaVergiNo, Set&lt;Sube&gt; subes, Set&lt;Anlasma&gt; anlasmas, Set&lt;Marka&gt; markas) {
          this.sektor = sektor;
          this.firmaUnvan = firmaUnvan;
          this.firmaVergiDairesi = firmaVergiDairesi;
          this.firmaVergiNo = firmaVergiNo;
          this.subes = subes;
          this.anlasmas = anlasmas;
          this.markas = markas;
      }
  
      @Id
      @GeneratedValue(strategy = IDENTITY)
      @Column(name = "firmaId", unique = true, nullable = false)
      public Integer getFirmaId() {
          return this.firmaId;
      }
  
      public void setFirmaId(Integer firmaId) {
          this.firmaId = firmaId;
      }
  
      @ManyToOne(fetch = FetchType.LAZY)
      @JoinColumn(name = "firmaSektorId")
      public Sektor getSektor() {
          return this.sektor;
      }
  
      public void setSektor(Sektor sektor) {
          this.sektor = sektor;
      }
  
      @Column(name = "firmaUnvan")
      public String getFirmaUnvan() {
          return this.firmaUnvan;
      }
  
      public void setFirmaUnvan(String firmaUnvan) {
          this.firmaUnvan = firmaUnvan;
      }
  
      @Column(name = "firmaVergiDairesi")
      public String getFirmaVergiDairesi() {
          return this.firmaVergiDairesi;
      }
  
      public void setFirmaVergiDairesi(String firmaVergiDairesi) {
          this.firmaVergiDairesi = firmaVergiDairesi;
      }
  
      @Column(name = "firmaVergiNo", length = 11)
      public String getFirmaVergiNo() {
          return this.firmaVergiNo;
      }
  
      public void setFirmaVergiNo(String firmaVergiNo) {
          this.firmaVergiNo = firmaVergiNo;
      }
  
      @OneToMany(fetch = FetchType.LAZY, mappedBy = "firma")
      public Set&lt;Sube&gt; getSubes() {
          return this.subes;
      }
  
      public void setSubes(Set&lt;Sube&gt; subes) {
          this.subes = subes;
      }
  
      @OneToMany(fetch = FetchType.LAZY, mappedBy = "firma")
      public Set&lt;Anlasma&gt; getAnlasmas() {
          return this.anlasmas;
      }
  
      public void setAnlasmas(Set&lt;Anlasma&gt; anlasmas) {
          this.anlasmas = anlasmas;
      }
  
      @OneToMany(fetch = FetchType.LAZY, mappedBy = "firma")
      public Set&lt;Marka&gt; getMarkas() {
          return this.markas;
      }
  
      public void setMarkas(Set&lt;Marka&gt; markas) {
          this.markas = markas;
  }
  </code></pre>
  
  <p>GenericDao.java </p>
  
  <pre><code>public interface GenericDao&lt;E, PK extends Serializable&gt; 
  {
  PK save(E newInstance);
  
  void update(E transientObject);
  
  void saveOrUpdate(E transientObject);
  
  void delete(E persistentObject);
  
  E findById(PK id);
  
  List&lt;E&gt; findAll();
  
  List&lt;E&gt; findAllByProperty(String propertyName, Object value);
  }
  </code></pre>
  
  <p>GenericDaoImpl.java</p>
  
  <pre><code>    public abstract class GenericDaoImpl&lt;E, PK extends Serializable&gt; extends HibernateDaoSupport implements GenericDao&lt;E, PK&gt;
  {
  
  
  @SuppressWarnings("unchecked")
  public PK save(E newInstance) {
      return (PK) getHibernateTemplate().save(newInstance);
  }
  
  public E findById(PK id) {
      return (E) getHibernateTemplate().get(getEntityClass(), id);
  }
  
  @SuppressWarnings("unchecked")
  public List&lt;E&gt; findAll() {
      return getHibernateTemplate().findByCriteria(createDetachedCriteria());
  }
  
  @SuppressWarnings("unchecked")
  public List&lt;E&gt; findAllByProperty(String propertyName, Object value) {
      DetachedCriteria criteria = createDetachedCriteria();
      criteria.add(Restrictions.eq(propertyName, value));
      return getHibernateTemplate().findByCriteria(criteria);
  }
  
  @SuppressWarnings("unchecked")
  public List&lt;E&gt; findByExample(E object) {
      List&lt;E&gt; resultList = getHibernateTemplate().findByExample(object, 0, 1);
      return resultList;
  }
  
  @SuppressWarnings("unchecked")
  public List&lt;E&gt; findByExample(E object, int firstResult, int maxResults) {
      List&lt;E&gt; resultList = getHibernateTemplate().findByExample(object,
              firstResult, maxResults);
      return resultList;
  }
  
  public void update(E transientObject) {
      getHibernateTemplate().update(transientObject);
  }
  
  public void saveOrUpdate(E transientObject) {
      getHibernateTemplate().saveOrUpdate(transientObject);
  }
  
  public void delete(E persistentObject) {
      getHibernateTemplate().delete(persistentObject);
  }
  
  protected abstract Class&lt;E&gt; getEntityClass();
  
  protected DetachedCriteria createDetachedCriteria() {
      return DetachedCriteria.forClass(getEntityClass());
  }
  }
  </code></pre>
  
  <p>FirmaHome.java</p>
  
  <pre><code>public class FirmaHome extends GenericDaoImpl&lt;Firma, Integer&gt; {
  
  @Override
  protected Class&lt;Firma&gt; getEntityClass() {
      return Firma.class;
  }
  }
  </code></pre>