9 Replies Latest reply on Jun 1, 2009 5:01 AM by Waqas Arshad

    %%%% Error Creating SessionFactory %%%%

    Waqas Arshad Novice

      I changed one of my table *.hbm.xml, just to make my feild auto increment whenever an insert is made:

      <generator class="increment"/>
      

      and since them i am getting the exception
      %%%% Error Creating SessionFactory %%%%
      org.hibernate.MappingException: Error reading resource: table/detail/Detail.hbm.xml
       at org.hibernate.cfg.Configuration.addResource(Configuration.java:452)
       at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1263)
       at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1235)
       at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1217)
       at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1184)
       at org.hibernate.cfg.Configuration.configure(Configuration.java:1112)
       at sessionFactory.HibernateSessionFactory.<clinit>(HibernateSessionFactory.java:30)
       at table.detail.BaseHibernateDAO.getSession(BaseHibernateDAO.java:14)
       at table.detail.DetailDAO.findByProperty(DetailDAO.java:83)
       at table.detail.DetailDAO.findByWord(DetailDAO.java:93)
       at ecs.dictionary.Dictionary.searchWord(Dictionary.java:45)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
       at java.lang.reflect.Method.invoke(Unknown Source)
       at org.apache.el.parser.AstValue.invoke(AstValue.java:152)
       at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:276)
       at org.apache.jasper.el.JspMethodExpression.invoke(JspMethodExpression.java:68)
       at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:88)
       at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
       at javax.faces.component.UICommand.broadcast(UICommand.java:387)
       at org.ajax4jsf.component.AjaxActionComponent.broadcast(AjaxActionComponent.java:55)
       at org.ajax4jsf.component.AjaxViewRoot.processEvents(AjaxViewRoot.java:321)
       at org.ajax4jsf.component.AjaxViewRoot.broadcastEvents(AjaxViewRoot.java:296)
       at org.ajax4jsf.component.AjaxViewRoot.processPhase(AjaxViewRoot.java:253)
       at org.ajax4jsf.component.AjaxViewRoot.processApplication(AjaxViewRoot.java:466)
       at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:82)
       at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
       at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
       at javax.faces.webapp.FacesServlet.service(FacesServlet.java:265)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
       at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:178)
       at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
       at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:390)
       at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:517)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
       at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
       at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
       at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
       at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
       at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
       at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
       at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
       at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
       at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
       at java.lang.Thread.run(Unknown Source)
      Caused by: org.hibernate.MappingException: invalid mapping
       at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:399)
       at org.hibernate.cfg.Configuration.addResource(Configuration.java:449)
       ... 47 more
      Caused by: org.xml.sax.SAXParseException: Attribute "generated" must be declared for element type "property".
       at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
       at org.apache.xerces.util.ErrorHandlerWrapper.error(Unknown Source)
       at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
       at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
       at org.apache.xerces.impl.dtd.XMLDTDValidator.addDTDDefaultAttrsAndValidate(Unknown Source)
       at org.apache.xerces.impl.dtd.XMLDTDValidator.handleStartElement(Unknown Source)
       at org.apache.xerces.impl.dtd.XMLDTDValidator.startElement(Unknown Source)
       at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)
       at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
       at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
       at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
       at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
       at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
       at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
       at org.dom4j.io.SAXReader.read(SAXReader.java:465)
       at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:398)
       ... 48 more
      


        • 1. Re: %%%% Error Creating SessionFactory %%%%
          Dmitry Geraskov Newbie

          Exception is:
          org.xml.sax.SAXParseException: Attribute "generated" must be declared for element type "property".

          Seems like you are using wrong context for element. Give the mapping code with parent of element.

          • 2. Re: %%%% Error Creating SessionFactory %%%%
            Waqas Arshad Novice

            *.cfg.xml

            <?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">
            
            <!-- Generated by MyEclipse Hibernate Tools. -->
            <hibernate-configuration>
            
            <session-factory>
             <property name="myeclipse.connection.profile">
             OracleDriver
             </property>
             <property name="connection.url">
             jdbc:oracle:thin:@localhost:1521:orcl
             </property>
             <property name="connection.username">dictionary</property>
             <property name="connection.password">eee</property>
             <property name="connection.driver_class">
             oracle.jdbc.driver.OracleDriver
             </property>
             <property name="dialect">
             org.hibernate.dialect.Oracle9Dialect
             </property>
             <mapping resource="table/suggestion/Suggestion.hbm.xml" />
             <mapping resource="table/detail/Detail.hbm.xml" />
            
            </session-factory>
            
            </hibernate-configuration>
            


            detail.hbm.xml
            <?xml version="1.0" encoding="utf-8"?>
            <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
             "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
            <!--
             Mapping file autogenerated by MyEclipse Persistence Tools
            -->
            <hibernate-mapping>
             <class name="table.detail.Detail" schema="DICTIONARY" table="DETAIL">
             <id name="wordId" type="java.lang.String">
             <column length="10" name="WORD_ID"/>
             <generator class="increment"/>
             </id>
             <property generated="never" lazy="false" name="word" type="java.lang.String">
             <column length="100" name="WORD" not-null="true"/>
             </property>
             <property generated="never" lazy="false" name="description" type="java.lang.String">
             <column length="1000" name="DESCRIPTION" not-null="true"/>
             </property>
             <property generated="never" lazy="false" name="status" type="java.lang.String">
             <column length="1" name="STATUS" not-null="true"/>
             </property>
             </class>
            </hibernate-mapping>
            


            • 3. Re: %%%% Error Creating SessionFactory %%%%
              Dmitry Geraskov Newbie

              Give me Suggestion.hbm.xml.

              • 4. Re: %%%% Error Creating SessionFactory %%%%
                Waqas Arshad Novice

                 

                <?xml version="1.0" encoding="utf-8"?>
                <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
                "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
                <!--
                 Mapping file autogenerated by MyEclipse Persistence Tools
                -->
                <hibernate-mapping>
                 <class name="table.suggestion.Suggestion" table="SUGGESTION" schema="DICTIONARY">
                 <composite-id name="id" class="table.suggestion.SuggestionId">
                 <key-property name="word" type="java.lang.String">
                 <column name="WORD" length="100" />
                 </key-property>
                 <key-property name="description" type="java.lang.String">
                 <column name="DESCRIPTION" length="1000" />
                 </key-property>
                 </composite-id>
                 </class>
                </hibernate-mapping>
                


                • 5. Re: %%%% Error Creating SessionFactory %%%%
                  Waqas Arshad Novice

                  okay removing 'generated' from the property element in detail.hbm.xml done the trick. But these XML files were created by MyEclipse itself and this 'generated' attribute was also added by MyEclipse. So i am bit confused why this error was comming up?
                  I also want to know that i have wordId in detail.hbm.xml of type String. I want to make it auto increment so that whenever an insert is made in the table it generates the key itself. How to solve this?

                  • 6. Re: %%%% Error Creating SessionFactory %%%%
                    Dmitry Geraskov Newbie

                    Hm... I created java files with all field types String, and getters/setters for them and SessionFactory is built. I only use other dialect, but I think it doesn't matter.

                    • 7. Re: %%%% Error Creating SessionFactory %%%%
                      Dmitry Geraskov Newbie

                      Oracle support siquence. Use it for generating unique id. Why you want to use String as id? Or you don't want to change generated files? It is better to chenage id-type to something better, for example int/Integer. How to use generators see in hibernate documentation, for example here: http://docs.jboss.org/hibernate/stable/core/reference/en/html_single/#mapping-declaration-id-generator

                      • 8. Re: %%%% Error Creating SessionFactory %%%%
                        Waqas Arshad Novice

                        yes that was the mistake i did. NOw i changed the ID type to Number(oracle number). When i did the reverse engineering it made the ID of BigDecimal type. Now when i try to insert a record it gives me exception:

                        SEVERE: org.hibernate.id.IdentifierGenerationException: this id generator generates long, integer, short
                        javax.faces.el.EvaluationException: org.hibernate.id.IdentifierGenerationException: this id generator generates long, integer, short
                         at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:102)
                         at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
                         at javax.faces.component.UICommand.broadcast(UICommand.java:387)
                         at javax.faces.component.UIData.broadcast(UIData.java:938)
                         at org.ajax4jsf.component.AjaxViewRoot.processEvents(AjaxViewRoot.java:321)
                         at org.ajax4jsf.component.AjaxViewRoot.broadcastEvents(AjaxViewRoot.java:296)
                         at org.ajax4jsf.component.AjaxViewRoot.processPhase(AjaxViewRoot.java:253)
                         at org.ajax4jsf.component.AjaxViewRoot.processApplication(AjaxViewRoot.java:466)
                         at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:82)
                         at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
                         at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
                         at javax.faces.webapp.FacesServlet.service(FacesServlet.java:265)
                         at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
                         at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
                         at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:178)
                         at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
                         at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:390)
                         at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:517)
                         at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
                         at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
                         at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
                         at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
                         at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
                         at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
                         at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
                         at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
                         at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
                         at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
                         at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
                         at java.lang.Thread.run(Unknown Source)
                        Caused by: org.hibernate.id.IdentifierGenerationException: this id generator generates long, integer, short
                         at org.hibernate.id.IdentifierGeneratorFactory.createNumber(IdentifierGeneratorFactory.java:119)
                         at org.hibernate.id.IncrementGenerator.generate(IncrementGenerator.java:47)
                         at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:85)
                         at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:184)
                         at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:33)
                         at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:173)
                         at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:27)
                         at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:69)
                         at org.hibernate.impl.SessionImpl.save(SessionImpl.java:481)
                         at org.hibernate.impl.SessionImpl.save(SessionImpl.java:476)
                         at table.detail.DetailDAO.save(DetailDAO.java:32)
                         at ecs.admin.InsertSuggestion.insert(InsertSuggestion.java:121)
                         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                         at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
                         at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
                         at java.lang.reflect.Method.invoke(Unknown Source)
                         at org.apache.el.parser.AstValue.invoke(AstValue.java:152)
                         at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:276)
                         at org.apache.jasper.el.JspMethodExpression.invoke(JspMethodExpression.java:68)
                         at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:88)
                         ... 29 more