-->
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.  [ 1 post ] 
Author Message
 Post subject: Playing with setFlushMode in IdentifierGenerator.generate()
PostPosted: Fri Sep 10, 2004 6:37 am 
Expert
Expert

Joined: Thu Jan 29, 2004 2:31 am
Posts: 362
Location: Switzerland, Bern
Hi

I have written my own IdentifierGenerator in order to map to a legacy DB.
Since the generate method needs to access the db fields, hibernate trys to flush the session before executing the querry, which in term calls the generate method ... until I get a StackOverflow.

In order to prevent this I changed the flush mode before the query, which seams to work fine. My question is if this is legal to do so in a read/write session?

TIA
Enrst


generate Method of my IdentifierGenerator:
Code:
   public Serializable generate(SessionImplementor session, Object object)
               throws SQLException, HibernateException {
      try {
         Class clazz = object.getClass();
         Query q = session.createQuery(
            "select max(capiPkClass.myPk.id) " +
               "from "+clazz.getName()+" as capiPkClass " +
               "where capiPkClass.myPk.systemId="+TransactionManager.getSystemId());
         FlushMode fm = session.getFlushMode();
         session.setFlushMode(FlushMode.NEVER);
         List l = q.list();
         session.setFlushMode(fm);
         long maxPID = ((Long)l.get(0)).longValue();
         CapiPK pk = new CapiPK(TransactionManager.getSystemId(), maxPID+1);
         if (LOG.isDebugEnabled()) {
            LOG.debug("new PK:"+pk+", for instance: "+ new ReflectionToStringBuilder(object).toString());
         }
         return pk;
      } catch (SecurityException e) {




Hibernate version:
2.1.4
Mapping documents:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd"><hibernate-mapping>
   <class name="ch.bedag.gba.cap.server.business.model.grundstueck.OPerson" table="TBE">
      <id name="myPk" type="ch.bedag.gba.cap.server.persistence.hibernate.CapiPkType" access="field">
         <column name="FBE01" sql-type="systemId" not-null="true"/>
         <column name="FBE02" sql-type="id" not-null="true"/>
         <generator class="ch.bedag.gba.cap.server.persistence.hibernate.CapiIdentifierGenerator"/>
      </id>
        <property name="myAhvNummer" column="FBE03" access="field"/>
...
      <set name="myOPersonAdresse" table="TBB" cascade="all-delete-orphan" inverse="true" access="field">
         <key>
            <column name="FBB01"/>
            <column name="FBB03"/>
         </key>
         <one-to-many class="ch.bedag.gba.cap.server.business.model.grundstueck.OPersonAdresse"/>
      </set>      
   </class>
</hibernate-mapping>


Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd"><hibernate-mapping>
   <class name="ch.bedag.gba.cap.server.business.model.grundstueck.OPersonAdresse" table="TBB">
      <id name="myPk" type="ch.bedag.gba.cap.server.persistence.hibernate.CapiPkType" access="field">
         <column name="FBB01" sql-type="systemId" not-null="true"/>
         <column name="FBB02" sql-type="id" not-null="true"/>
         <generator class="ch.bedag.gba.cap.server.persistence.hibernate.CapiIdentifierGenerator"/>
      </id>
...
      <many-to-one name="myOPerson" class="ch.bedag.gba.cap.server.business.model.grundstueck.OPerson"
            update="false" insert="false" access="field" not-null="true">
         <column name="FBB01"/>
         <column name="FBB03"/>
      </many-to-one>
      <property name="myOPersonPID" column="FBB03" access="field" not-null="true"/>
      <many-to-one name="Gemeinde" class="ch.bedag.gba.cap.server.business.model.grundstueck.Gemeinde"
            update="false" insert="false">
         <column name="FBB01"/>
         <column name="FBB09"/>
      </many-to-one>
   </class>
</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():
Code:
         Session s = HibernateUtil.getInstance().getSession();
         HibernateUtil.getInstance().beginTransaction();
         
         OPerson p = new OPerson();
         OPersonAdresse a = new OPersonAdresse();
         p.getOPersonAdresse().add(a);
         a.setOPerson(p);
         
         s.save(p);

         HibernateUtil.getInstance().commitTransaction();


Full stack trace of any exception that occurs:
n/a

Name and version of the database you are using:
Oracle 9.2

The generated SQL (show_sql=true):
Code:
Hibernate: select max(operson0_.FBE02) as x0_0_ from TBE operson0_ where (operson0_.FBE01=903 )
10.09.2004 12:24:24 FEIN    CapiIdentifierGenerator    generate: new PK:ch.bedag.gba.cap.server.persistence.hibernate.CapiPK@17e53c9[mySystemId=903,myId=1151,isUnsaved=true], for instance: ch.bedag.gba.cap.server.business.model.grundstueck.OPerson@17c50b9[myPk=<null>,myAhvNummer=<null>,myAnrede=<null>,myGeburtsDatum=<null>,myName1=<null>,myName2=<null>,myName3=<null>,myName4=<null>,myName5=<null>,myName6=<null>,myName7=<null>,myPersonArt=0,mySitz=<null>,mySprachCode=0,myPersonKuerzel=<null>,myGueltig=0,myGeburtsjahr=<null>,myVerheiratet=<null>,myHeimatort=<null>,myNoOCP=<null>,myDecedeQuitte=<null>,myDateDecedeQuitte=<null>,myBlockageMiseAJourPersonne=<null>,mySexe=<null>,myClientRegulier=<null>,myNoSCC=<null>,myNrAci=<null>,myNrIrole=<null>,myGrundUngueltig=<null>,myStatus=<null>,myAciMutationsArt=<null>,myOPersonAdresse=[ch.bedag.gba.cap.server.business.model.grundstueck.OPersonAdresse@1042c25[
  myPk=<null>
  myOPersonPID=<null>
...
  myReferenzAdresse=<null>
  myOPerson=ch.bedag.gba.cap.server.business.model.grundstueck.OPerson@17c50b9myGemeinde=<null>
]]]
Hibernate: select max(opersonadr0_.FBB02) as x0_0_ from TBB opersonadr0_ where (opersonadr0_.FBB01=903 )
10.09.2004 12:24:24 FEIN    CapiIdentifierGenerator    generate: new PK:ch.bedag.gba.cap.server.persistence.hibernate.CapiPK@d0d843[mySystemId=903,myId=1113,isUnsaved=true], for instance: ch.bedag.gba.cap.server.business.model.grundstueck.OPersonAdresse@1042c25[myPk=<null>,myOPersonPID=<null>,myStrasse1=<null>,myStrasse2=<null>,myPlz=<null>,myOrt=<null>,myLandesKennziffer=<null>,myAdressArt=<null>,myAnrede=<null>,myName1=<null>,myName2=<null>,myName3=<null>,myAciMutationsArt=<null>,myLand=<null>,myBlockageMiseAJuarAdresse=<null>,myReferenzPlz=<null>,myReferenzOrt=<null>,myReferenzStrasse1=<null>,myReferenzStrasse2=<null>,myReferenzLand=<null>,myReferenzAdresse=<null>,myOPerson=ch.bedag.gba.cap.server.business.model.grundstueck.OPerson@17c50b9[
  myPk=ch.bedag.gba.cap.server.persistence.hibernate.CapiPK@17e53c9[mySystemId=903,myId=1151,isUnsaved=true]
  myAhvNummer=<null>
... 
myAciMutationsArt=<null>
  myOPersonAdresse=[ch.bedag.gba.cap.server.business.model.grundstueck.OPersonAdresse@1042c25[
  ch.bedag.gba.cap.server.business.model.grundstueck.OPersonAdresse@1042c25ch.bedag.gba.cap.server.business.model.grundstueck.OPersonAdresse@1042c25
]]
],myGemeinde=<null>]
10.09.2004 12:24:24 FEIN    HibernateUtil    commitTransaction: Committing database transaction of this thread.
Hibernate: insert into TBE (FBE03, FBE04, FBE05, FBE07, FBE08, FBE09, FBE32, FBE33, FBE34, FBE35, FBE10, FBE11, FBE12, FBE14, FBE15, FBE16, FBE17, FBE18, FBE23, FBE24, FBE25, FBE26, FBE27, FBE28, FBE29, FBE30, FBE31, FBE37, FBE38, FBE41, FBE01, FBE02) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
10.09.2004 12:24:24 FEIN    CapiPkType    nullSafeSet: ch.bedag.gba.cap.server.persistence.hibernate.CapiPK@17e53c9[mySystemId=903,myId=1151,isUnsaved=true]
10.09.2004 12:24:24 FEIN    CapiPkType    nullSafeSet: ch.bedag.gba.cap.server.persistence.hibernate.CapiPK@d0d843[mySystemId=903,myId=1113,isUnsaved=true]
Hibernate: insert into TBB (FBB05, FBB06, FBB07, FBB08, FBB10, FBB12, FBB13, FBB14, FBB15, FBB16, FBB20, FBB21, FBB23, FBB24, FBB25, FBB26, FBB27, FBB28, FBB29, FBB03, FBB01, FBB02) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)



Debug level Hibernate log excerpt:
see above


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

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.