8 Replies Latest reply on Aug 30, 2012 9:03 AM by ctomc

    forcing specific type mapping/dialect for datasource

    mclu

      In the past for Jboss 4.2.3 we had this mssql-ds.xml in our deploy dir and there we defined the type mapping like this.

       

      <datasources>

        <local-tx-datasource>

           .....

          <type-mapping>MS SQLSERVER2000</type-mapping>

        </local-tx-datasource>

       

      As well as we set the property hibernate.dialect=XXXX

      at deploy\ejb3.deployer\META-INF\persistence.properties

       

      If I am not wrong this forced Hibernate to use the right dialect.

       

      How can I do the same with Jboss 7.1.1.

      I defined a module with my driver and use it inside my standalone.xml.

       

      Everything works perfect but there are special cases where I want to force hibernate to use a dialect.

       

      First one is the lack of autodetect SQLServer2010 dialect

      second: I have some issues with setMaxResults() on a query which maybe is not translated right to my current SQLServer 2008.

       

      So my question:

      How to force a dialect.

       

      Thx Markus Lutum

        • 1. Re: forcing specific type mapping/dialect for datasource
          nickarls

          A property in persistence.xml sounds like it would do the job.

          • 2. Re: forcing specific type mapping/dialect for datasource
            mclu

            Thx Nicklas!

             

            Problem is that we have a product where we support various databases. We have multiple persistence.xml files in multiple jars inside the ear.

            While installing our product we don't want to change or alter our packed ear. Only the jboss configuration was changed in the past by our installer.....

            So if there is a "global" way to force it plz let me know.

             

            Markus

            • 3. Re: forcing specific type mapping/dialect for datasource
              nickarls

              Don't recall seeing type-mapping for datasources on AS7 (somebody else probably knows more). We build with maven so for our similar case we just have different profiles that filter the xml files...

              • 4. Re: forcing specific type mapping/dialect for datasource
                mclu

                By the way... The setMaxResult() issue is solved. It was not the mapping.

                If you set this to  Integer.MAX_VALUE because the user has no upper limit I got this exception:

                javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: Invalid parameter index 2.

                 

                It seams that there is an overflow. Maybe related to https://hibernate.onjira.com/browse/HHH-5699

                 

                If i simply substract some numbers like Integer.MAX_VALUE-1000 then it works.

                 

                Just if someone has the same issue and this thread is a google hit :-)

                 

                Greets

                • 5. Re: forcing specific type mapping/dialect for datasource
                  ctomc

                  Hi,

                   

                  type-mapping that used to be part of -ds.xml was only used for CMP persistence which you do not use.

                   

                  Best and proper solution is what Niclas suggested, that is to set hibernate.dialect in persistence.xml / hibernate.cfg.xml

                   

                  If you are using persistence.xml you can use system propery resolving inside them with syntax ${name.of.property} in that case you could define system properties for server and you would not need to modify the deployment for different server.

                  You are talking about sql server 2010? are you sure, you probably mean 2008r2 or 2012 that just came out.

                   

                  when you will have dialect properly set, probably your issue will go away.

                   

                  --

                  tomaz

                  • 6. Re: forcing specific type mapping/dialect for datasource
                    nickarls

                    Cool, never though about the ${}-expansion, does it work automagically in all the xml files in a deployment or just some?

                    • 7. Re: forcing specific type mapping/dialect for datasource
                      mclu

                      Yepp Thomaz...

                       

                      My mistake... its 2012 not 2010

                      and there is already a jira for this issue : https://hibernate.onjira.com/browse/HHH-7522

                      And thx for the property idea... mabe this could be a solution!

                      • 8. Re: forcing specific type mapping/dialect for datasource
                        ctomc

                        Nicklas,

                        it was added around 7.1.1/7.1.2 i am not sure anymore when exactly.

                        but basicly you can control what can be replaced in ee subsystem

                         

                        basicly it can be replaced in all descriptors, by default in jboss descriptors, for spec defined descriptors you have to enable them...

                         

                        ee subystem config is quite self explinatory abou this

                         

                        <subsystem xmlns="urn:jboss:domain:ee:1.1">

                                <spec-descriptor-property-replacement>false</spec-descriptor-property-replacement>

                                <jboss-descriptor-property-replacement>true</jboss-descriptor-property-replacement>

                           </subsystem>

                         

                         

                        --

                        tomaz