Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    SmartGWT + Hibernate + Spring configuration problem

    v8.2p_2012-08-26/Pro Deployment (built 2012-08-26)
    Hibernate 3.6.1
    Spring 3.1.2

    What i am trying to do is to make smartgwt buildinds example work with hibernate through spring.

    things are quite simple:

    web.xml
    Code:
    <context-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>
                classpath:/applicationContext-resources.xml
                classpath:/applicationContext-dao.xml
                ...
            </param-value>
        </context-param>
    applicationContext-resources.xml
    Code:
    <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
            <property name="ignoreUnresolvablePlaceholders" value="true"/>
            <property name="locations">
                <list>
                    <value>classpath:jdbc.properties</value>
                </list>
            </property>
        </bean>
    
        <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
            <property name="driverClassName" value="${jdbc.driverClassName}"/>
            <property name="url" value="${jdbc.url}"/>
            <property name="username" value="${jdbc.username}"/>
            <property name="password" value="${jdbc.password}"/>
            <property name="maxActive" value="100"/>
            <property name="maxWait" value="1000"/>
            <property name="poolPreparedStatements" value="true"/>
            <property name="defaultAutoCommit" value="true"/>
        </bean>
    jdbc.properties
    Code:
    jdbc.driverClassName=net.sourceforge.jtds.jdbc.Driver
    jdbc.url=jdbc:jtds:sqlserver://172.16.0.16:1433/system
    jdbc.username=sa
    jdbc.password=555
    hibernate.dialect=org.hibernate.dialect.SQLServerDialect
    applicationContext-dao.xml
    Code:
    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
            <property name="dataSource" ref="dataSource"/>
            <property name="configLocation" value="classpath:hibernate.cfg.xml"/>
            <property name="hibernateProperties">
                <value>
                    hibernate.dialect=${hibernate.dialect}
                    hibernate.jdbc.use_streams_for_binary=true
                    hibernate.jdbc.use_streams_for_binary=0
                </value>
            </property>
        </bean>
    and in server.properties
    Code:
    hibernate.config.lookupStyle: spring
    hibernate.config.bean: sessionFactory
    hibernate.cfg.xml itself contains no confiuration, it's going to hold references to hibernate beans.

    As the result in the log file i see 2 consecutive Hibernate initializations, 1- success, 2 - failure:
    Code:
    INFO  Dialect - Using dialect: org.hibernate.dialect.SQLServerDialect
    ....
    DEBUG SessionFactoryObjectFactory - initializing class SessionFactoryObjectFactory
    DEBUG SessionFactoryObjectFactory - registered: a1e116cf-7d6d-46d4-b7f9-a55508e1c7e2 (unnamed)
    
    ....
    
    ERROR DataSourceLoader - Exception while attempting to load a DataSource
    org.hibernate.HibernateException: 'hibernate.dialect' must be set when no Connection available
    What am i doing wrong or what smartGwt doing wrong? Thx in advance.

    Full log file is attached (RENAME TXT TO ZIP, i was not able to upload 90kb txt or .zip).

    2. And small question in addtition:
    Am i getting it right from some old forum posts about old versions, that it's not possible to force build-in hibernate datasource to work with sping session factory and transaction management and it only reads configuration from provided spring bean? Or things changed nowadays?
    Attached Files
    Last edited by vostapenko; 29 Aug 2012, 15:43.

    #2
    Couldn't say what's wrong with so little detail (not even a .ds.xml or full log), but there's no point to this, as there's a separate sample that already shows Hibernate.

    Comment


      #3
      Full log is attached to original message.

      users.ds.xml
      Code:
      <DataSource ID="users" serverType="hibernate" tableName="suser">
          <fields>
              <field name="userid" title="ID" type="integer" primaryKey="true" required="true"/>
              <field name="userlogin" title="Login" type="text"/>
              <field name="userpassword" title="Password" type="text"/>
          </fields>
      </DataSource>
      I've looked through "separate samples". In all samples (at least in sdk examples) hibernate is configured through hibernate.cfg.xml, so it's a different story and i'm reporting about the issue with hibernate.config.lookupStyle: spring
      Last edited by vostapenko; 29 Aug 2012, 15:55.

      Comment


        #4
        You are most likely running into a situation where Spring tries to initialize itself before SmartGWT even if configured for lazy creation - see this thread for a workaround. This workaround has already been applied for 3.1d.

        Comment


          #5
          Reproduced on 3.1d (SNAPSHOT_v8.3d_2012-08-30/Pro Deployment (built 2012-08-30))
          Last edited by vostapenko; 30 Aug 2012, 02:08.

          Comment


            #6
            From my point of view, the problem is caused by SmartGWT still caring about hibernate.cfg.xml even when

            Code:
            hibernate.config.lookupStyle: spring
            hibernate.config.bean: mySessionFactory
            is specified. I think SmartGwt should ignore hibernate.cfg.xml completely. I've attached new full logs with srping debug if you need them.

            Please confirm.
            Attached Files
            Last edited by vostapenko; 30 Aug 2012, 04:39.

            Comment


              #7
              Btw, the workaround for this is renaming hibernate.cfg.xml and changing sessionfactory declaration to something like

              Code:
                  <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
                      <property name="dataSource" ref="dataSource"/>
                      <property name="configLocation" value="classpath:hibernate3.cfg.xml"/>
                      <property name="hibernateProperties">
                          <value>
                              hibernate.dialect=${hibernate.dialect}
                          </value>
                      </property>
                  </bean>
              But you should definitely fix this issue, "hibernate.config.lookupStyle: spring" doesn't work with hibernate.cfg.xml on classpath with no config parameters inside.

              And, Isomorphic, pls don't be so haughty answering users questions. Your forum support already has bad rep across the internet. Try to change something. BTW i'm reporting bugs and making your product better, and i'm doing it for free.

              Comment


                #8
                Can you clarify what the issue is - you seem to be saying an empty hibernate.cfg.xml on the classpath causes a problem, but now you seem to be using Spring to load settings from a hibernate.cfg.xml file that has been renamed but presumably has some settings in it.

                Are you trying to use *both* Spring-based config and a hibernate.cfg.xml file, but you don't want SmartGWT to read the hibernate.cfg.xml file directly?

                As far as support, we appreciate that your intent is to report bugs, however please realize that we have known bugs we can be working on. It's not uncommon to spend a lot of time helping someone who is having an odd problem only to discover there's no bug and not even a documentation clarification worth adding; when this happens the time would have been better spent on actual bugs.

                Also, don't believe everything you read. Fake reviews are very affordable these days, just like fake Twitter followers :)

                Comment


                  #9
                  hibernate.cfg.xml contains only mapping, e.g.

                  Code:
                  <hibernate-configuration>
                      <session-factory>
                          <mapping class="com.smartgwt.mypackage.User"/>
                      </session-factory>
                  </hibernate-configuration>
                  All connection settings are moved to jdbc.properties, and read by PropertyPlaceholderConfigurer.

                  PropertyPlaceholderConfigurer -> DataSource bean -> Sessionfactory bean.

                  With this configuration, smartgwt tries to use hibernate.cfg.xml even it's clearly instructed to load config properties via spring (hibernate.config.lookupStyle: spring). It should completely ignore hibernate.cfg.xml.
                  Last edited by vostapenko; 4 Sep 2012, 18:01.

                  Comment


                    #10
                    What's actually going on here is that we loaded your configuration via Spring, but it did not contain a mapping for the class you specified in your DataSource.

                    In this situation we assumed you wanted a dynamic mapping added (which is something the framework supports). The only way for us to add a dynamic mapping is to have the configuration expressed as a hibernate.cfg.xml file because the configuration returned by Spring is immutable.

                    So the real problem was that your Spring configuration was incomplete - it lacked the required mapping. Your changes fixed the problem by making the mapping available through Spring - the fact that you renamed hibernate.cfg.xml was unimportant as it would not have been consulted anyway once you corrected your Spring config.

                    Let us know if you disagree with this analysis - there doesn't appear to be a bug here but we might add some logs to make it clearer why you would see an attempt to rebuild the config.

                    Comment


                      #11
                      Thx for your reply.

                      The real problem was that your Spring configuration was incomplete - it lacked the required mapping.
                      Well, from my point of view, my configuration was ok. Mapping was included in session factory bean declaration.

                      Code:
                      <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
                              <property name="dataSource" ref="dataSource"/>
                              [b]<property name="configLocation" value="classpath:hibernate.cfg.xml"/>[/b]
                              <property name="hibernateProperties">
                                  <value>
                                      hibernate.dialect=${hibernate.dialect}
                                  </value>
                              </property>
                          </bean>
                      Your changes fixed the problem by making the mapping available through Spring - the fact that you renamed hibernate.cfg.xml was unimportant
                      The only change i made was renaming config file to hibernate3.cfg.xml and changing corresponding config declaration to <property name="configLocation" value="classpath:hibernate3.cfg.xml"/>.

                      So, to summarize, my configuration contained mapping from the beginning. The only change i made is renaming hibernate config. So i've never "corrected" my configuration as you state.

                      Comment


                        #12
                        Hi,

                        You have to correct your data source definition:

                        Code:
                        <DataSource
                            ID="users"
                            serverType="hibernate"
                            tableName="suser"    <--- remove this property
                            beanClassName="com.smartgwt.mypackage.User"  <--- add this property
                        >
                            <fields>
                                <field name="userid" title="ID" type="integer" primaryKey="true" required="true"/>
                                <field name="userlogin" title="Login" type="text"/>
                                <field name="userpassword" title="Password" type="text"/>
                            </fields>
                        </DataSource>
                        Bit of explanation:
                        "beanClassName" property specifies ORM mapped class which should be used in data source.
                        If you specify only "tableName" property then data source does not know which class to use and tries to create mapping on the fly.

                        Regards,
                        Alius

                        Comment


                          #13
                          Code:
                          You have to correct your data source definition
                          I have correct definition. Earlier provided definition was in context of dinamic model (hibernate.cfg.xml did not contain any mapping, but the file was present).

                          Code:
                          <DataSource
                              ID="users"
                              serverType="hibernate"
                              tableName="suser"
                          >
                          without mapping in hibernate.cfg.xml

                          and

                          Code:
                          <DataSource
                              ID="users"
                              serverType="hibernate"
                              beanClassName="com.smartgwt.mypackage.User"
                          with mapping

                          gives the same error we are already discussing - the problem of SmartGWT not ignoring hibernate.cfg xml, while full hibernate configureation is passed to it with the help of spring.

                          Comment


                            #14
                            Could you post your class, data source, hibernate.cfg.xml, related options from server.properties, related configuration from spring?
                            Please post server log which you get with that configuration as well.

                            Thanks,
                            Alius

                            Comment


                              #15
                              Actually, i've lost interest to this problem, because renaming hibernate.cfg.xml works pretty well. If noone before experienced the same problem, maybe it's not even worth fixing.

                              I'm now far ahead in the develpment and reproducing it againg with clean logs is gonna need some effort.

                              I'll try to do it a little later.

                              Your help is very appreciated anyway.

                              Comment

                              Working...
                              X