1 Reply Latest reply on Sep 15, 2005 8:10 AM by Patrik Meisinger

    could not initialize a collection

    Patrik Meisinger Newbie

      after deploying (which works fine) my application i start my application (rich client platform application) and get the following error.

      12:22:36,280 ERROR [JDBCExceptionReporter] line 1, Table 'om_okopf' owned by 'ingres' does not contain column 'cross1'.
      12:22:36,370 INFO [STDOUT] java.lang.RuntimeException: org.jboss.tm.JBossRollbackException: Unable to commit, tx=TransactionImpl:XidImpl[FormatId=257, GlobalId=PC110/29, BranchQual=, localId=29] status=STATUS_NO_TRANSACTION; - nested throwable: (org.hibernate.exception.SQLGrammarException: could not initialize a collection: [ams.ingres.model.PvStamp.omOcros#100585])


      my relations look like this:
      PvStamp(1)<->(*)OmOcros(*)<->(1)OmOkopf(1)<->(*)OmOpos

      the sql joins for the relations are:
      PvStamp.ident = OmOcros.cross_1
      OmOkopf.objekt = OmOcros.objekt
      OmOkopf.objekt = OmOpos.objekt

      PvStamp.java looks like this:
      @Entity
      @Table (name="PV_STAMP")
      public class PvStamp implements Serializable {
       private Integer ident;
       private Collection<OmOcros> omOcros = new HashSet();
      
      // ... some properties
      
       @Id
       @Column (name = "IDENT")
       public Integer getIdent() {
       return ident;
       }
       public void setIdent(Integer ident) {
       this.ident = ident;
       }
      
       @OneToMany (targetEntity=ams.ingres.model.OmOcros.class, cascade=CascadeType.ALL,
       mappedBy="pvStamp")
       @JoinColumn (name="ident", referencedColumnName="cross1")
       public Collection<OmOcros> getOmOcros() {
       return (Collection<OmOcros>)omOcros;
       }
       public void setOmOcros(Collection<OmOcros> omOcros) {
       this.omOcros = (Collection <OmOcros>) omOcros;
       }
      }
      

      OmOcross.java
      @Entity
      @Table (name="OM_OKOPF")
      
      public class OmOcros {
       private Integer objekt;
       private Integer cross1;
       // ... some properties
       private Collection<OmOkopf> omOkopf = new HashSet();
       private Collection<PvStamp> pvStamp = new HashSet();
      
       @Id
       @Column (name="OBJEKT")
       public Integer getObjekt() {
       return objekt;
       }
       public void setObjekt(Integer objekt) {
       this.objekt = objekt;
       }
      // ... some setters/getters
       @ManyToOne (targetEntity=ams.ingres.model.PvStamp.class, cascade=CascadeType.ALL)
       @JoinColumn(name="objekt", referencedColumnName="objekt")
       public OmOkopf getOmOkopf() {
       return omOkopf;
       }
       public void setOmOkopf(OmOkopf omOkopf) {
       this.omOkopf = omOkopf;
       }
      
       @ManyToOne (targetEntity=ams.ingres.model.PvStamp.class, cascade=CascadeType.ALL)
       @JoinColumn(name="cross1", referencedColumnName="ident")
       public PvStamp getPvStamp() {
       return pvStamp;
       }
       public void setPvStamp(PvStamp pvStamp) {
       this.pvStamp = pvStamp;
       }
      }
      

      OmOkopf.java
      @Entity
      @Table (name="OM_OKOPF")
      
      public class OmOkopf {
       private Integer objekt;
       private Collection<OmOpos> omOpos = new HashSet();
       private Collection<OmOcros> omOcros = new HashSet();
      // ... some properties
       @Id
       @Column (name="OBJEKT")
       public Integer getObjekt() {
       return objekt;
       }
       public void setObjekt(Integer objekt) {
       this.objekt = objekt;
       }
      
      // ... some setters/getters
       @OneToMany(targetEntity=ams.ingres.model.OmOpos.class, cascade=CascadeType.ALL,
       mappedBy="omOkopf")
       @JoinColumn(name="objekt")
       public Collection<OmOpos> getOmOpos() {
       return (Collection <OmOpos>) omOpos;
       }
      
       public void setOmOpos(Collection<OmOpos> omOpos) {
       this.omOpos = omOpos;
       }
      
       @OneToMany(targetEntity=ams.ingres.model.OmOcros.class, cascade=CascadeType.ALL,
       mappedBy="omOkopf")
       @JoinColumn(name="objekt")
       public Collection<OmOcros> getOmOcros() {
       return (Collection <OmOcros>) omOcros;
       }
      
       public void setOmOcros(Collection<OmOcros> omOcros) {
       this.omOcros = omOcros;
       }
      }
      

      OmOpos.java
      @Entity
      @Table (name="OM_OKOPF")
      public class OmOpos {
       private Integer ident;
       private Collection<OmOkopf> omOkopf = new HashSet();
      // ... some properties
      
       @Id
       @Column (name="IDENT")
       public int getIdent() {
       return ident;
       }
       public void setIdent(Integer ident) {
       this.ident = ident;
       }
      // ... some setters/getters
       @ManyToOne(targetEntity=ams.ingres.model.OmOpos.class, cascade=CascadeType.ALL)
       @JoinColumn(name="objekt")
       public OmOkopf getOmOkopf() {
       return omOkopf;
       }
       public void setOmOkopf(OmOkopf omOkopf) {
       this.omOkopf = omOkopf;
       }
      }
      


      full stack-trace of the exception:
      12:22:36,280 ERROR [JDBCExceptionReporter] line 1, Table 'om_okopf' owned by 'ingres' does not contain column 'hallo'.
      12:22:36,370 INFO [STDOUT] java.lang.RuntimeException: org.jboss.tm.JBossRollbackException: Unable to commit, tx=TransactionImpl:XidImpl[FormatId=257, GlobalId=PC110/29, BranchQual=, localId=29] status=STATUS_NO_TRANSACTION; - nested throwable: (org.hibernate.exception.SQLGrammarException: could not initialize a collection: [ams.ingres.model.PvStamp.omOcros#100585])
      12:22:36,370 INFO [STDOUT] at org.jboss.aspects.tx.TxPolicy.handleEndTransactionException(TxPolicy.java:185)
      12:22:36,370 INFO [STDOUT] at org.jboss.aspects.tx.TxPolicy.endTransaction(TxPolicy.java:167)
      12:22:36,370 INFO [STDOUT] at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:74)
      12:22:36,370 INFO [STDOUT] at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:134)
      12:22:36,370 INFO [STDOUT] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:88)
      12:22:36,370 INFO [STDOUT] at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:72)
      12:22:36,370 INFO [STDOUT] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:88)
      12:22:36,370 INFO [STDOUT] at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:39)
      12:22:36,370 INFO [STDOUT] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:88)
      12:22:36,370 INFO [STDOUT] at org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:63)
      12:22:36,370 INFO [STDOUT] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:88)
      12:22:36,370 INFO [STDOUT] at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:93)
      12:22:36,370 INFO [STDOUT] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:88)
      12:22:36,370 INFO [STDOUT] at org.jboss.ejb3.stateless.StatelessContainer.dynamicInvoke(StatelessContainer.java:183)
      12:22:36,370 INFO [STDOUT] at org.jboss.aop.Dispatcher.invoke(Dispatcher.java:107)
      12:22:36,370 INFO [STDOUT] at org.jboss.aspects.remoting.AOPRemotingInvocationHandler.invoke(AOPRemotingInvocationHandler.java:69)
      12:22:36,370 INFO [STDOUT] at org.jboss.remoting.ServerInvoker.invoke(ServerInvoker.java:325)
      12:22:36,370 INFO [STDOUT] at org.jboss.remoting.ServerInvoker.invoke(ServerInvoker.java:201)
      12:22:36,370 INFO [STDOUT] at org.jboss.remoting.transport.socket.ServerThread.processInvocation(ServerThread.java:259)
      12:22:36,370 INFO [STDOUT] at org.jboss.remoting.transport.socket.ServerThread.dorun(ServerThread.java:313)
      12:22:36,370 INFO [STDOUT] at org.jboss.remoting.transport.socket.ServerThread.run(ServerThread.java:147)
      12:22:36,370 INFO [STDOUT] Caused by: org.jboss.tm.JBossRollbackException: Unable to commit, tx=TransactionImpl:XidImpl[FormatId=257, GlobalId=PC110/29, BranchQual=, localId=29] status=STATUS_NO_TRANSACTION; - nested throwable: (org.hibernate.exception.SQLGrammarException: could not initialize a collection: [ams.ingres.model.PvStamp.omOcros#100585])
      12:22:36,370 INFO [STDOUT] at org.jboss.tm.TransactionImpl.commit(TransactionImpl.java:354)
      12:22:36,370 INFO [STDOUT] at org.jboss.aspects.tx.TxPolicy.endTransaction(TxPolicy.java:162)
      12:22:36,370 INFO [STDOUT] ... 19 more
      12:22:36,370 INFO [STDOUT] Caused by: org.hibernate.exception.SQLGrammarException: could not initialize a collection: [ams.ingres.model.PvStamp.omOcros#100585]
      12:22:36,370 INFO [STDOUT] at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:59)
      12:22:36,370 INFO [STDOUT] at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
      12:22:36,370 INFO [STDOUT] at org.hibernate.loader.Loader.loadCollection(Loader.java:1706)
      12:22:36,370 INFO [STDOUT] at org.hibernate.loader.collection.CollectionLoader.initialize(CollectionLoader.java:36)
      12:22:36,370 INFO [STDOUT] at org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:490)
      12:22:36,370 INFO [STDOUT] at org.hibernate.event.def.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:60)
      12:22:36,370 INFO [STDOUT] at org.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:1437)
      12:22:36,370 INFO [STDOUT] at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:219)
      12:22:36,370 INFO [STDOUT] at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:81)
      12:22:36,370 INFO [STDOUT] at org.hibernate.collection.PersistentBag.iterator(PersistentBag.java:246)
      12:22:36,370 INFO [STDOUT] at org.hibernate.type.CollectionType.getElementsIterator(CollectionType.java:197)
      12:22:36,370 INFO [STDOUT] at org.hibernate.type.CollectionType.getElementsIterator(CollectionType.java:189)
      12:22:36,370 INFO [STDOUT] at org.hibernate.engine.CascadingAction.getAllElementsIterator(CascadingAction.java:243)
      12:22:36,370 INFO [STDOUT] at org.hibernate.engine.CascadingAction.access$100(CascadingAction.java:21)
      12:22:36,370 INFO [STDOUT] at org.hibernate.engine.CascadingAction$8.getCascadableChildrenIterator(CascadingAction.java:205)
      12:22:36,370 INFO [STDOUT] at org.hibernate.engine.Cascade.cascadeCollectionElements(Cascade.java:286)
      12:22:36,370 INFO [STDOUT] at org.hibernate.engine.Cascade.cascadeCollection(Cascade.java:183)
      12:22:36,370 INFO [STDOUT] at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:158)
      12:22:36,370 INFO [STDOUT] at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:106)
      12:22:36,370 INFO [STDOUT] at org.hibernate.engine.Cascade.cascade(Cascade.java:246)
      12:22:36,370 INFO [STDOUT] at org.hibernate.event.def.AbstractFlushingEventListener.cascadeOnFlush(AbstractFlushingEventListener.java:124)
      12:22:36,370 INFO [STDOUT] at org.hibernate.event.def.AbstractFlushingEventListener.prepareEntityFlushes(AbstractFlushingEventListener.java:115)
      12:22:36,370 INFO [STDOUT] at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:62)
      12:22:36,370 INFO [STDOUT] at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:26)
      12:22:36,370 INFO [STDOUT] at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:736)
      12:22:36,370 INFO [STDOUT] at org.hibernate.ejb.AbstractEntityManagerImpl.flush(AbstractEntityManagerImpl.java:183)
      12:22:36,370 INFO [STDOUT] at org.jboss.ejb3.entity.ManagedEntityManagerFactory$SessionSynchronization.beforeCompletion(ManagedEntityManagerFactory.java:88)
      12:22:36,370 INFO [STDOUT] at org.jboss.tm.TransactionImpl.doBeforeCompletion(TransactionImpl.java:1473)
      12:22:36,370 INFO [STDOUT] at org.jboss.tm.TransactionImpl.beforePrepare(TransactionImpl.java:1092)
      12:22:36,370 INFO [STDOUT] at org.jboss.tm.TransactionImpl.commit(TransactionImpl.java:306)
      12:22:36,370 INFO [STDOUT] ... 20 more
      12:22:36,370 INFO [STDOUT] Caused by: ca.edbc.util.EdbcEx: line 1, Table 'om_okopf' owned by 'ingres' does not contain column 'hallo'.
      12:22:36,370 INFO [STDOUT] at ca.edbc.jdbc.EdbcObj.readResults(EdbcObj.java:785)
      12:22:36,370 INFO [STDOUT] at ca.edbc.jdbc.EdbcPrep.prepare(EdbcPrep.java:692)
      12:22:36,370 INFO [STDOUT] at ca.edbc.jdbc.EdbcPrep.<init>(EdbcPrep.java:328)
      12:22:36,370 INFO [STDOUT] at ca.edbc.jdbc.EdbcConnect.prepareStatement(EdbcConnect.java:1134)
      12:22:36,370 INFO [STDOUT] at org.jboss.resource.adapter.jdbc.BaseWrapperManagedConnection.prepareStatement(BaseWrapperManagedConnection.java:360)
      12:22:36,370 INFO [STDOUT] at org.jboss.resource.adapter.jdbc.WrappedConnection.prepareStatement(WrappedConnection.java:205)
      12:22:36,370 INFO [STDOUT] at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:395)
      12:22:36,370 INFO [STDOUT] at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:334)
      12:22:36,370 INFO [STDOUT] at org.hibernate.jdbc.AbstractBatcher.prepareQueryStatement(AbstractBatcher.java:88)
      12:22:36,370 INFO [STDOUT] at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1426)
      12:22:36,370 INFO [STDOUT] at org.hibernate.loader.Loader.doQuery(Loader.java:637)
      12:22:36,370 INFO [STDOUT] at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:221)
      12:22:36,370 INFO [STDOUT] at org.hibernate.loader.Loader.loadCollection(Loader.java:1699)
      12:22:36,370 INFO [STDOUT] ... 47 more
      


      the problem is caused by the following line in OmOcros.java:
      @JoinColumn(name="cross1", referencedColumnName="ident")
      it tells me that that the table OmOkopf does not contain the property cross1. of course not, because it's in OmOcross, where it should be. this line of code is for the join where PvStamp.ident = OmOcros.cross1. i've no idea why OmOkopf is affected.

      i'm using eclipse3.1, hibernate 3.1, jboss4.0.3RC1 with ejb3.0, jdk1.5, jbosside1.5M2, hibernatetools 3.1alpha5.

      what could be the solution to this? any help is appreciated.

      thanks in advance
      best regards
      patrik