-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: Memory leak Hibernate as JPA provider under JSE
PostPosted: Wed Oct 21, 2009 8:19 am 
Beginner
Beginner

Joined: Sat Feb 16, 2008 3:09 pm
Posts: 24
Hallo, I am trying to use Hibernate (hibernate-distribution-3.3.2.GA, hibernate-annotations-3.4.0.GA, hibernate-entitymanager-3.4.0.GA) in an JSE application as JPA provider.
I get a memory leak. Heap dump analysis shows that
SessionFactoryObjectFactory is the culprit.

Quote:
The class "org.hibernate.impl.SessionFactoryObjectFactory", loaded by "<system class loader>", occupies 29.196.584 (97,80%) bytes. The memory is accumulated in one instance of "java.util.HashMap$Entry[]" loaded by "<system class loader>".


Any ideas what might cause this would be greatly appreciated.

persistence.xml
Code:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
    http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">

<persistence-unit name="bafoeg3">
      <properties>
         <property name="hibernate.ejb.cfgfile" value="/hibernate.cfg.xml" />
      </properties>
</persistence-unit>
</persistence>


hibernate.cfg.xml:
Code:
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
          "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
          "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
   <property name="connection.url">jdbc:postgresql://localhost/bafoeg3</property>
   <property name="connection.username">postgres</property>
   <property name="connection.driver_class">org.postgresql.Driver</property>
   <property name="dialect">org.hibernate.dialect.PostgreSQLDialect</property>
   <property name="connection.password">danet123</property>
   <!-- 
<property name="transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>-->
   
    <property name="hibernate.c3p0.min_size">5</property>
    <property name="hibernate.c3p0.max_size">20</property>
    <property name="hibernate.c3p0.timeout">300</property>
    <property name="hibernate.c3p0.max_statements">50</property>
    <property name="hibernate.c3p0.idle_test_period">3000</property>
    <property name="current_session_context_class">thread</property>
    <!-- this will show us all sql statements -->
    <property name="hibernate.show_sql">true</property>
   <property name="hibernate.format_sql">true</property>
   
</session-factory>
</hibernate-configuration>


Example Code
Code:
public class FallDAO {

   public void saveFall(Fall fall) {
      EntityManagerFactory emf = Persistence.createEntityManagerFactory("bla");
      EntityManager entityManager = emf.createEntityManager();
      EntityTransaction tx = entityManager.getTransaction();
      tx.begin();
      entityManager.persist(fall);
      tx.commit();
      entityManager.close();
   }
}


Code:
public class FallBuilder extends Builder implements FallBuilderI  {
   
   private BewilligungszeitraumBuilderI bewilligungszeitraumBuilder;
   
   private EntityManager entityManager;

   public FallBuilder() {
      super();
      this.bewilligungszeitraumBuilder = new BewilligungszeitraumBuilder();
      EntityManagerFactory emf = Persistence.createEntityManagerFactory("bafoeg3");
      this.entityManager = emf.createEntityManager();
   }

   public Fall buildFall(Akt akt) {
      Fall fall = new Fall();
      
      primitiveMapping(fall, akt);
      
      //TODO fall.setBescheidEmpfaenger(value);
      
      if ( akt.getAltAmtBlKrz() != null &&  akt.getAltAmtBlKrz().length() > 0) {
         Query query = entityManager.createNamedQuery( "findBundeslandByValue" );
         query.setParameter( "value", akt.getAltAmtBlKrz() );
         Bundesland bundesland = (Bundesland) query.getSingleResult();
         fall.setAltAmtBundesland(bundesland);
      }
                .........................



Code:
package bafoeg21.dbaccess.domain;

import javax.persistence.FetchType;

@javax.persistence.NamedQueries({
@javax.persistence.NamedQuery( name="findZeitraumsbescheidendeFallIDs", query="SELECT DISTINCT f.id  FROM Fall f WHERE EXISTS ( SELECT b1.id FROM Bewilligungszeitraum b1 WHERE b1.geaendert > :stichtag AND b1.sondersachverhalt.value <> 'WEITER_50' AND f.id = b1.fall.id ) OR EXISTS ( SELECT b2.id FROM Bewilligungszeitraum b2 WHERE b2.geaendert > :stichtag AND b2.sondersachverhalt IS NULL AND f.id = b2.fall.id ) OR EXISTS ( SELECT c1.id FROM EinmaligeAenderung c1 WHERE c1.fall.id = f.id AND c1.umwandlungBankInStaatsfoerderung = 'true' AND c1.monatslauf.zeitstempel IS NULL ) OR EXISTS ( SELECT f1.id FROM Fall f1 JOIN f1.zahlungen z1 WHERE f1.id = f.id AND z1.monatslauf.zeitstempel = :stichtag AND f1.lastErgebnis.verrechnungsrate <> z1.verrechnungsrate )" ),
@javax.persistence.NamedQuery( name="findAmtIDsAnstehenderZahlungZuMonat", query="SELECT DISTINCT f.amt.id FROM Fall f INNER JOIN f.bewilligungszeitraeume b WHERE ((f.lastErgebnis.monatslauf.zahlmonat = :zahlmonat AND (f.lastErgebnis.zahlbetragImZahlmonat > 0.0 OR f.lastErgebnis.nachzahlungGesamt > 0.0)) OR (b.beginn <= :zahlmonat AND b.ende >= :zahlmonat AND f.lastErgebnis.zahlbetragLaufend > 0.0))" ),
@javax.persistence.NamedQuery( name="findFallIDsAnstehenderZahlungZuMonatUndAmt", query="SELECT DISTINCT f.id FROM Fall f INNER JOIN f.bewilligungszeitraeume b WHERE ( ((f.lastErgebnis.monatslauf.zahlmonat = :zahlmonat AND (f.lastErgebnis.zahlbetragImZahlmonat > 0.0 OR f.lastErgebnis.nachzahlungGesamt > 0.0)) OR (b.beginn <= :zahlmonat AND b.ende >= :zahlmonat AND f.lastErgebnis.zahlbetragLaufend > 0.0))  AND (f.amt.id = :amtid) )" ),
@javax.persistence.NamedQuery( name="findFallCorresponding", query="SELECT e.id FROM Fall e WHERE e.foerdernummer = :foerdernummer " )
})

@javax.persistence.Entity
@javax.persistence.Table( name="tbe_fall" )
public class Fall implements java.io.Serializable {
  private static final org.apache.log4j.Logger log = org.apache.log4j.Logger.getLogger( Fall.class );
  private static javax.persistence.EntityManager em = null;
 
  @javax.persistence.Id @javax.persistence.GeneratedValue
  @javax.persistence.Column( name="fall_id" )
  protected long id;
  public long getId() {
    return id;
  }

  @javax.persistence.Column( name="akt_geaendert" )
  private java.lang.Boolean geaendert = null;
  public java.lang.Boolean getGeaendert() {
    return geaendert;
  }
  public void setGeaendert( java.lang.Boolean value ) {
    geaendert = value;
  }

  @javax.persistence.ManyToOne(fetch = FetchType.LAZY, cascade={ javax.persistence.CascadeType.MERGE, javax.persistence.CascadeType.PERSIST, javax.persistence.CascadeType.REFRESH } )
  @javax.persistence.JoinColumn( name="akt_amt_id" )
  private bafoeg21.dbaccess.domain.Amt amt = null;
  public bafoeg21.dbaccess.domain.Amt getAmt() {
    return amt;
  }
  public void setAmt( bafoeg21.dbaccess.domain.Amt value ) {
    amt = value;
  }

  @javax.persistence.ManyToOne(fetch = FetchType.LAZY, cascade={ javax.persistence.CascadeType.MERGE, javax.persistence.CascadeType.PERSIST, javax.persistence.CascadeType.REFRESH } )
  @javax.persistence.JoinColumn( name="akt_azu_id" )
  private bafoeg21.dbaccess.domain.Auszubildender auszubildender = null;
  public bafoeg21.dbaccess.domain.Auszubildender getAuszubildender() {
    return auszubildender;
  }
  public void setAuszubildender( bafoeg21.dbaccess.domain.Auszubildender value ) {
    auszubildender = value;
  }

  @javax.persistence.ManyToOne(fetch = FetchType.LAZY, cascade={ javax.persistence.CascadeType.MERGE, javax.persistence.CascadeType.PERSIST, javax.persistence.CascadeType.REFRESH } )
  @javax.persistence.JoinColumn( name="akt_adrgar_id" )
  private bafoeg21.dbaccess.domain.Adressgarant adressgarant = null;
  public bafoeg21.dbaccess.domain.Adressgarant getAdressgarant() {
    return adressgarant;
  }
  public void setAdressgarant( bafoeg21.dbaccess.domain.Adressgarant value ) {
    adressgarant = value;
  }

  @javax.persistence.ManyToOne(fetch = FetchType.LAZY, cascade={ javax.persistence.CascadeType.MERGE, javax.persistence.CascadeType.PERSIST, javax.persistence.CascadeType.REFRESH } )
  @javax.persistence.JoinColumn( name="akt_bempf_id" )
  private bafoeg21.dbaccess.domain.Bescheidempfaenger bescheidEmpfaenger = null;
  public bafoeg21.dbaccess.domain.Bescheidempfaenger getBescheidEmpfaenger() {
    return bescheidEmpfaenger;
  }
  public void setBescheidEmpfaenger( bafoeg21.dbaccess.domain.Bescheidempfaenger value ) {
    bescheidEmpfaenger = value;
  }

  @javax.persistence.ManyToOne(fetch = FetchType.LAZY, cascade={ javax.persistence.CascadeType.MERGE, javax.persistence.CascadeType.PERSIST, javax.persistence.CascadeType.REFRESH } )
  @javax.persistence.JoinColumn( name="akt_drempf_id" )
  private bafoeg21.dbaccess.domain.Drittempfaenger drittempfaenger = null;
  public bafoeg21.dbaccess.domain.Drittempfaenger getDrittempfaenger() {
    return drittempfaenger;
  }
  public void setDrittempfaenger( bafoeg21.dbaccess.domain.Drittempfaenger value ) {
    drittempfaenger = value;
  }

  @javax.persistence.ManyToOne(fetch = FetchType.LAZY)
  @javax.persistence.JoinColumn( name="akt_altamt_bl" )
  private bafoeg21.dbaccess.domain.Bundesland altAmtBundesland = null;
  public bafoeg21.dbaccess.domain.Bundesland getAltAmtBundesland() {
    return altAmtBundesland;
  }
  public void setAltAmtBundesland( bafoeg21.dbaccess.domain.Bundesland value ) {
    altAmtBundesland = value;
  }

  @javax.persistence.Column( name="akt_altamt_nr", length=3 )
  private java.lang.String altAmtNummer = null;
  public java.lang.String getAltAmtNummer() {
    return altAmtNummer;
  }
  public void setAltAmtNummer( java.lang.String value ) {
    altAmtNummer = value;
  }

  @javax.persistence.Column( name="akt_alt_fnr" )
  private java.lang.String alteFoerderungsnummer = null;
  public java.lang.String getAlteFoerderungsnummer() {
    return alteFoerderungsnummer;
  }
  public void setAlteFoerderungsnummer( java.lang.String value ) {
    alteFoerderungsnummer = value;
  }

  @javax.persistence.Column( name="akt_foerdernr" )
  private java.lang.String foerdernummer = null;
  public java.lang.String getFoerdernummer() {
    return foerdernummer;
  }
  public void setFoerdernummer( java.lang.String value ) {
    foerdernummer = value;
  }

  @javax.persistence.Column( name="akt_drempf_zweck", length=200 )
  private java.lang.String zweckDrittempfaenger = null;
  public java.lang.String getZweckDrittempfaenger() {
    return zweckDrittempfaenger;
  }
  public void setZweckDrittempfaenger( java.lang.String value ) {
    zweckDrittempfaenger = value;
  }

  @javax.persistence.Column( name="akt_drz_kuerzel" )
  private java.lang.Boolean lfdZahlungDrittempfaenger = null;
  public java.lang.Boolean getLfdZahlungDrittempfaenger() {
    return lfdZahlungDrittempfaenger;
  }
  public void setLfdZahlungDrittempfaenger( java.lang.Boolean value ) {
    lfdZahlungDrittempfaenger = value;
  }

  @javax.persistence.Column( name="akt_zahlstop_datum" )
  private java.lang.String zahlstopDatum = null;
  public java.lang.String getZahlstopDatumValue() {
    return zahlstopDatum;
  }
  public bafoeg21.commons.types.YearMonth getZahlstopDatum() {
    return new bafoeg21.commons.types.YearMonth( zahlstopDatum );
  }
  public void setZahlstopDatumValue( java.lang.String value ) {
    zahlstopDatum = value;
  }

  public void setZahlstopDatum( bafoeg21.commons.types.YearMonth value ) {
    if( value == null ) {
      setZahlstopDatumValue( null );
    } else {
      setZahlstopDatumValue( value.toString());
    }
  }

  @javax.persistence.Column( name="akt_sb_dbuser_id", length=30 )
  private java.lang.String sachbearbeiterId = null;
  public java.lang.String getSachbearbeiterId() {
    return sachbearbeiterId;
  }
  public void setSachbearbeiterId( java.lang.String value ) {
    sachbearbeiterId = value;
  }

  @javax.persistence.Column( name="akt_al_dbuser_id", length=30 )
  private java.lang.String gruppenleiterId = null;
  public java.lang.String getGruppenleiterId() {
    return gruppenleiterId;
  }
  public void setGruppenleiterId( java.lang.String value ) {
    gruppenleiterId = value;
  }

  @javax.persistence.Column( name="akt_fall_abgegb" )
  private java.lang.Boolean fallAbgegeben = null;
  public java.lang.Boolean getFallAbgegeben() {
    return fallAbgegeben;
  }
  public void setFallAbgegeben( java.lang.Boolean value ) {
    fallAbgegeben = value;
  }

  @javax.persistence.Column( name="akt_fall_angenm" )
  private java.lang.Boolean fallAngenommen = null;
  public java.lang.Boolean getFallAngenommen() {
    return fallAngenommen;
  }
  public void setFallAngenommen( java.lang.Boolean value ) {
    fallAngenommen = value;
  }

  @javax.persistence.Column( name="akt_ehem_bd" )
  private java.lang.Boolean ehemaligBankdarlehen = null;
  public java.lang.Boolean getEhemaligBankdarlehen() {
    return ehemaligBankdarlehen;
  }
  public void setEhemaligBankdarlehen( java.lang.Boolean value ) {
    ehemaligBankdarlehen = value;
  }

  @javax.persistence.Column( name="akt_zweitstudium" )
  private java.lang.Boolean zweitstudium = null;
  public java.lang.Boolean getZweitstudium() {
    return zweitstudium;
  }
  public void setZweitstudium( java.lang.Boolean value ) {
    zweitstudium = value;
  }

  @javax.persistence.Column( name="akt_bva_zw_prkt" )
  private java.lang.String foerderungshoechstdauer = null;
  public java.lang.String getFoerderungshoechstdauerValue() {
    return foerderungshoechstdauer;
  }
  public bafoeg21.commons.types.YearMonth getFoerderungshoechstdauer() {
    return new bafoeg21.commons.types.YearMonth( foerderungshoechstdauer );
  }
  public void setFoerderungshoechstdauerValue( java.lang.String value ) {
    foerderungshoechstdauer = value;
  }

  public void setFoerderungshoechstdauer( bafoeg21.commons.types.YearMonth value ) {
    if( value == null ) {
      setFoerderungshoechstdauerValue( null );
    } else {
      setFoerderungshoechstdauerValue( value.toString());
    }
  }

  @javax.persistence.Column( name="akt_bd_ktonr", length=12 )
  private java.lang.String kontonummerBankdarlehen = null;
  public java.lang.String getKontonummerBankdarlehen() {
    return kontonummerBankdarlehen;
  }
  public void setKontonummerBankdarlehen( java.lang.String value ) {
    kontonummerBankdarlehen = value;
  }

  @javax.persistence.Column( name="akt_bd_vertrdat" )
  private java.sql.Date vertragsdatumBankdarlehen = null;
  public java.sql.Date getVertragsdatumBankdarlehen() {
    return vertragsdatumBankdarlehen;
  }
  public void setVertragsdatumBankdarlehen( java.sql.Date value ) {
    vertragsdatumBankdarlehen = value;
  }

  @javax.persistence.Column( name="akt_bd_geaendert" )
  private java.sql.Timestamp kfwDatenGeaendert = null;
  public java.sql.Timestamp getKfwDatenGeaendert() {
    return kfwDatenGeaendert;
  }
  public void setKfwDatenGeaendert( java.sql.Timestamp value ) {
    kfwDatenGeaendert = value;
  }

  @javax.persistence.Column( name="akt_bd_zins_nom", length=4, precision=2 )
  private java.lang.Float zinssatzBankdarlehenNominal = null;
  public java.lang.Float getZinssatzBankdarlehenNominal() {
    return zinssatzBankdarlehenNominal;
  }
  public void setZinssatzBankdarlehenNominal( java.lang.Float value ) {
    zinssatzBankdarlehenNominal = value;
  }

  @javax.persistence.Column( name="akt_bd_zins_eff", length=4, precision=2 )
  private java.lang.Float zinssatzBankdarlehenEffektiv = null;
  public java.lang.Float getZinssatzBankdarlehenEffektiv() {
    return zinssatzBankdarlehenEffektiv;
  }
  public void setZinssatzBankdarlehenEffektiv( java.lang.Float value ) {
    zinssatzBankdarlehenEffektiv = value;
  }

  @javax.persistence.Column( name="akt_arfz_aufr" )
  private java.lang.Double betragaufrech = null;
  public java.lang.Double getBetragaufrech() {
    return betragaufrech;
  }
  public void setBetragaufrech( java.lang.Double value ) {
    betragaufrech = value;
  }

  @javax.persistence.Column( name="akt_arfz_aufr_dat" )
  private java.lang.String letzteaufrechnung = null;
  public java.lang.String getLetzteaufrechnungValue() {
    return letzteaufrechnung;
  }
  public bafoeg21.commons.types.YearMonth getLetzteaufrechnung() {
    return new bafoeg21.commons.types.YearMonth( letzteaufrechnung );
  }
  public void setLetzteaufrechnungValue( java.lang.String value ) {
    letzteaufrechnung = value;
  }

  public void setLetzteaufrechnung( bafoeg21.commons.types.YearMonth value ) {
    if( value == null ) {
      setLetzteaufrechnungValue( null );
    } else {
      setLetzteaufrechnungValue( value.toString());
    }
  }

  @javax.persistence.Column( name="akt_auslf_abger" )
  private java.lang.Double auslandsfoerderungAbgerechnet = null;
  public java.lang.Double getAuslandsfoerderungAbgerechnet() {
    return auslandsfoerderungAbgerechnet;
  }
  public void setAuslandsfoerderungAbgerechnet( java.lang.Double value ) {
    auslandsfoerderungAbgerechnet = value;
  }

  @javax.persistence.Column( name="akt_dat_bankda" )
  private java.lang.String datumErstmaligesBankdarlehen = null;
  public java.lang.String getDatumErstmaligesBankdarlehenValue() {
    return datumErstmaligesBankdarlehen;
  }
  public bafoeg21.commons.types.YearMonth getDatumErstmaligesBankdarlehen() {
    return new bafoeg21.commons.types.YearMonth( datumErstmaligesBankdarlehen );
  }
  public void setDatumErstmaligesBankdarlehenValue( java.lang.String value ) {
    datumErstmaligesBankdarlehen = value;
  }

  public void setDatumErstmaligesBankdarlehen( bafoeg21.commons.types.YearMonth value ) {
    if( value == null ) {
      setDatumErstmaligesBankdarlehenValue( null );
    } else {
      setDatumErstmaligesBankdarlehenValue( value.toString());
    }
  }

  @javax.persistence.ManyToOne(fetch = FetchType.LAZY)
  @javax.persistence.JoinColumn( name="akt_uebentsch" )
  private bafoeg21.dbaccess.domain.Ueberzahlungsentscheidung ueberzahlunsentscheidung = null;
  public bafoeg21.dbaccess.domain.Ueberzahlungsentscheidung getUeberzahlunsentscheidung() {
    return ueberzahlunsentscheidung;
  }
  public void setUeberzahlunsentscheidung( bafoeg21.dbaccess.domain.Ueberzahlungsentscheidung value ) {
    ueberzahlunsentscheidung = value;
  }

  @javax.persistence.ManyToOne(fetch = FetchType.LAZY, cascade={ javax.persistence.CascadeType.MERGE, javax.persistence.CascadeType.PERSIST, javax.persistence.CascadeType.REFRESH } )
  @javax.persistence.JoinColumn( name="akt_lstarb_id" )
  private bafoeg21.dbaccess.domain.ErgebnisRueckAbrechnung lastErgebnis = null;
  public bafoeg21.dbaccess.domain.ErgebnisRueckAbrechnung getLastErgebnis() {
    return lastErgebnis;
  }
  public void setLastErgebnis( bafoeg21.dbaccess.domain.ErgebnisRueckAbrechnung value ) {
    lastErgebnis = value;
  }

  @javax.persistence.OneToMany(fetch = FetchType.LAZY, mappedBy = "fall", cascade={ javax.persistence.CascadeType.MERGE, javax.persistence.CascadeType.PERSIST, javax.persistence.CascadeType.REFRESH } )
  private java.util.List<bafoeg21.dbaccess.domain.Bewilligungszeitraum> bewilligungszeitraeume = null;
  public java.util.List<bafoeg21.dbaccess.domain.Bewilligungszeitraum> getBewilligungszeitraeume() {
    return bewilligungszeitraeume;
  }
  public void setBewilligungszeitraeume( java.util.List<bafoeg21.dbaccess.domain.Bewilligungszeitraum> value ) {
    bewilligungszeitraeume = value;
  }

  @javax.persistence.OneToMany(fetch = FetchType.LAZY, mappedBy = "fall", cascade={ javax.persistence.CascadeType.MERGE, javax.persistence.CascadeType.PERSIST, javax.persistence.CascadeType.REFRESH } )
  private java.util.List<bafoeg21.dbaccess.domain.ErgebnisRueckAbrechnung> ergebnisse = null;
  public java.util.List<bafoeg21.dbaccess.domain.ErgebnisRueckAbrechnung> getErgebnisse() {
    return ergebnisse;
  }
  public void setErgebnisse( java.util.List<bafoeg21.dbaccess.domain.ErgebnisRueckAbrechnung> value ) {
    ergebnisse = value;
  }

  @javax.persistence.OneToMany(fetch = FetchType.LAZY, mappedBy = "fall", cascade={ javax.persistence.CascadeType.MERGE, javax.persistence.CascadeType.PERSIST, javax.persistence.CascadeType.REFRESH } )
  private java.util.List<bafoeg21.dbaccess.domain.Zahlung> zahlungen = null;
  public java.util.List<bafoeg21.dbaccess.domain.Zahlung> getZahlungen() {
    return zahlungen;
  }
  public void setZahlungen( java.util.List<bafoeg21.dbaccess.domain.Zahlung> value ) {
    zahlungen = value;
  }

  @javax.persistence.OneToMany(fetch = FetchType.LAZY, mappedBy = "fall", cascade={ javax.persistence.CascadeType.MERGE, javax.persistence.CascadeType.PERSIST, javax.persistence.CascadeType.REFRESH } )
  private java.util.List<bafoeg21.dbaccess.domain.EinmaligeAenderung> einmaligeAenderungen = null;
  public java.util.List<bafoeg21.dbaccess.domain.EinmaligeAenderung> getEinmaligeAenderungen() {
    return einmaligeAenderungen;
  }
  public void setEinmaligeAenderungen( java.util.List<bafoeg21.dbaccess.domain.EinmaligeAenderung> value ) {
    einmaligeAenderungen = value;
  }

  @javax.persistence.OneToMany(fetch = FetchType.LAZY, mappedBy = "fall", cascade={ javax.persistence.CascadeType.MERGE, javax.persistence.CascadeType.PERSIST, javax.persistence.CascadeType.REFRESH } )
  private java.util.List<bafoeg21.dbaccess.domain.Bescheid> bescheide = null;
  public java.util.List<bafoeg21.dbaccess.domain.Bescheid> getBescheide() {
    return bescheide;
  }
  public void setBescheide( java.util.List<bafoeg21.dbaccess.domain.Bescheid> value ) {
    bescheide = value;
  }

  @javax.persistence.OneToMany(fetch = FetchType.LAZY, mappedBy = "fall", cascade={ javax.persistence.CascadeType.MERGE, javax.persistence.CascadeType.PERSIST, javax.persistence.CascadeType.REFRESH } )
  private java.util.List<bafoeg21.dbaccess.domain.BvaLeiste> bvaLeisten = null;
  public java.util.List<bafoeg21.dbaccess.domain.BvaLeiste> getBvaLeisten() {
    return bvaLeisten;
  }
  public void setBvaLeisten( java.util.List<bafoeg21.dbaccess.domain.BvaLeiste> value ) {
    bvaLeisten = value;
  }

  @javax.persistence.OneToMany(fetch = FetchType.LAZY, mappedBy = "fall", cascade={ javax.persistence.CascadeType.MERGE, javax.persistence.CascadeType.PERSIST, javax.persistence.CascadeType.REFRESH } )
  private java.util.List<bafoeg21.dbaccess.domain.FehlerBankdarlehensfall> fehlerBankdarlehensfaelle = null;
  public java.util.List<bafoeg21.dbaccess.domain.FehlerBankdarlehensfall> getFehlerBankdarlehensfaelle() {
    return fehlerBankdarlehensfaelle;
  }
  public void setFehlerBankdarlehensfaelle( java.util.List<bafoeg21.dbaccess.domain.FehlerBankdarlehensfall> value ) {
    fehlerBankdarlehensfaelle = value;
  }


  public boolean findCorresponding() throws javax.naming.NamingException {
    if( getId() == 0 ) {
      if( em == null ) {
        javax.naming.Context ctx = new javax.naming.InitialContext();
        em = (javax.persistence.EntityManager)ctx.lookup( "java:/bafoeg3EntityManagerDBA" );
      }

      javax.persistence.Query query = em.createNamedQuery( "findFallCorresponding" );
      query.setParameter( "foerdernummer", foerdernummer );
      java.util.List<Long> erg = query.getResultList();
      if( erg != null && erg.size() > 0 ) {
        id = ((Long)erg.get( 0 )).longValue();
        log.info( "id gefunden: " + ((Long)erg.get( 0 )).toString());
        return true;
      }
    }
    return false;
  }
}


Top
 Profile  
 
 Post subject: Re: Memory leak Hibernate as JPA provider under JSE
PostPosted: Tue Oct 27, 2009 11:37 am 
Regular
Regular

Joined: Fri May 12, 2006 4:05 am
Posts: 106
Hi,

having a brief look over your code it seems like you're creating a new EntityManagerFactory for every save-operation and you're not even closing it - that's what is causing your problems.
EntityManagerFactories res. the underlying SessionFactories are veeeery expensive to create and use lots of resources, so you'll be running out of memory rather quickly.
So try to do it this way: create your EntityManagerFactory as a singleton at application-startup or when first used and keep it hanging around as long as your application is running, just creating new sessions from it when needed. This should take care of your problem.


Top
 Profile  
 
 Post subject: Re: Memory leak Hibernate as JPA provider under JSE
PostPosted: Tue Oct 27, 2009 12:04 pm 
Beginner
Beginner

Joined: Sat Feb 16, 2008 3:09 pm
Posts: 24
Thanks,

that wast the problem.


Top
 Profile  
 
 Post subject: Re: Memory leak Hibernate as JPA provider under JSE
PostPosted: Thu Nov 05, 2009 11:36 am 
Newbie

Joined: Thu Nov 05, 2009 11:31 am
Posts: 8
I didn't see this in your code but one thing that has bitten me more than once is the life of the persistence context. As the previous posting referred to, you should insure you actually close the EntityManager at some point. If you don't do that periodically, maybe after each commit or ever n commits either close the em or, at the very least, clear() it.

EntityManagerFactory creation is hugely expensive. I made that a singleton where each thread gets its own EntityManager. In this way, for my purposes I don't do the EMF creation but once and each thread in my program gets a unique persistence context. At program end I close all EntityManager instances. The latest bite I received from this is in a webservice I need to close() or, at least, clear() the EntityManager instance as a finally block in the doGet(). But, again, the EMF is only created with the singleton is initially created.

Your mileage may vary,

Walt


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.