10 Replies Latest reply on Oct 7, 2005 5:57 PM by Rene Lavoie

    Mysql

    Rene Lavoie Newbie

      I tried changing persistence to Mysql and the shema is not being created.

      Am I missing something?

      Copied mysql-connector-java-3.1.10-bin.jar to C:\jboss-jdk5-seam-403RC2\server\default\lib

      <datasources>
       <local-tx-datasource>
       <jndi-name>bookingDatasource</jndi-name>
       <connection-url>jdbc:mysql://localhost:3306/booking</connection-url>
       <driver-class>com.mysql.jdbc.Driver</driver-class>
       <user-name>root</user-name>
       <password></password>
       <metadata>
       <type-mapping>mySQL</type-mapping>
       </metadata>
       </local-tx-datasource>
      </datasources>
      

      <entity-manager>
      
       <name>bookingDatabase</name>
      
       <provider>org.hibernate.ejb.HibernatePersistence</provider>
      
       <jta-data-source>java:/bookingDatasource</jta-data-source>
      
       <properties>
       <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
       <property name="hibernate.case.use_query_cache">true</property>
       <property name="hibernate.show_sql">false</property>
       <property name="hibernate.hbm2ddl.auto">create</property>
       <property name="hibernate.connection.datasource" value="java:/bookingDatasource"/>
       </properties>
      
      </entity-manager>
      

      <?xml version="1.0" encoding="UTF-8"?>
      
      
      
      <deployment xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      
       xsi:schemaLocation="urn:jboss:bean-deployer bean-deployer_1_0.xsd"
      
       xmlns="urn:jboss:bean-deployer">
      
      
      
       <bean name="bookingDatasourceBootstrap" class="org.jboss.resource.adapter.jdbc.local.LocalTxDataSource">
      
       <property name="driverClass">com.mysql.jdbc.Driverr</property>
      
       <property name="connectionURL">jdbc:mysql://localhost:3306/booking</property>
      
       <property name="userName">root</property>
       <property name="password"></property>
       <property name="jndiName">java:/bookingDatasource</property>
      
       <property name="minSize">0</property>
      
       <property name="maxSize">10</property>
      
       <property name="blockingTimeout">1000</property>
      
       <property name="idleTimeout">100000</property>
      
       <property name="transactionManager"><inject bean="TransactionManager"/></property>
      
       <property name="cachedConnectionManager"><inject bean="CachedConnectionManager"/></property>
      
       <property name="initialContextProperties"><inject bean="InitialContextProperties"/></property>
      
       </bean>
      
      
      
       <bean name="bookingDatasource" class="java.lang.Object">
      
       <constructor factoryMethod="getDatasource">
      
       <factory bean="bookingDatasourceBootstrap"/>
      
       </constructor>
      
       </bean>
      </deployment>
      


        • 1. Re: Mysql
          Rene Lavoie Newbie

          Please ignore the extra r in :

          <property name="driverClass">com.mysql.jdbc.Driverr</property>


          Its correct in my file.

          • 2. Re: Mysql
            David Vestal Newbie

            I don't have an answer to solve your problem with MySQL. For quite a while I have had a lot of troubles getting everything to work with MySQL and JBoss. Just to try it I switched to using Postgresql, just changed the "MySQL specific" parts of some files and it just worked immediately. There are the Postgresql example files in the docs/ dir and I used those with slight changes and it works now. I'm not sure what my issue was with MySQL, but I tried forever to get it to work as it's what I use for everything other than JBoss. If you are able/willing to switch DB's it's worth a shot.

            • 3. Re: Mysql
              Gavin King Master

              Um, I find all this incredibly difficult to believe. Tens of thousands of people are using Hibernate with MySQL without any issues.

              Note that no-one posting in this thread has provided anything like enough information to help solve the problem.

              • 4. Re: Mysql
                Imre Oßwald Newbie

                Ok might be tens of thousands, but not me :)
                Still I could not resist to dig into this. And it really does not work with Lavoirs setup and the example as it is at the moment.

                So here are the required changes to make hibernate and mysql happy :D

                A)
                Change the property-tags:

                <property name="foo">bar</property> # WRONG: ignored
                <property name="foo" value="bar" /> # OK
                


                so this is how persistence.xml should look like (at least it worked for me):
                <entity-manager>
                 <name>bookingDatabase</name>
                 <provider>org.hibernate.ejb.HibernatePersistence</provider>
                
                 <jta-data-source>java:/bookingDatasource</jta-data-source>
                
                 <properties>
                 <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
                 <property name="hibernate.case.use_query_cache" value="true" />
                 <property name="hibernate.show_sql" value="true" />
                 <property name="hibernate.hbm2ddl.auto" value="create-drop" />
                 <property name="hibernate.connection.datasource" value="java:/bookingDatasource"/>
                 </properties>
                </entity-manager>


                B)
                After the changes in persistence.xml the tables where created and the first user (Gavin) was imported. But then I got an JDBCException.
                To solve this, remove the "blank" lines between the INSERT statements in import.sql
                (this error might os-dependent? I only tested it on Windows)

                I hope this helps

                PS:
                Is registering at jboss.com a hacking contest??? ;D
                I had to save the Eloqua-Page and modify the javascript to get me registered....


                • 5. Re: Mysql
                  Gavin King Master

                   

                  "ioss" wrote:

                  A)
                  Change the property-tags:

                  <property name="foo">bar</property> # WRONG: ignored
                  <property name="foo" value="bar" /> # OK
                  



                  Right, this is what the EJB spec says, and what the Seam examples use.

                  "ioss" wrote:

                  B)
                  After the changes in persistence.xml the tables where created and the first user (Gavin) was imported. But then I got an JDBCException.
                  To solve this, remove the "blank" lines between the INSERT statements in import.sql
                  (this error might os-dependent? I only tested it on Windows)


                  Yes, MySQL doesn't like empty statements. Note that the example app deploys and runs just fine if there is a failure from import.sql, the only thing broken is that there will be no test data in the database.


                  • 6. Re: Mysql
                    Rene Lavoie Newbie

                    Thanks ioss!

                    I m not sure how I ended up doing this, but I remember looking at some of my old hibernate.cfg.xml files, I must of copy/pasted some configs without realising the differences.

                    • 7. Re: Mysql
                      Chengyao Deng Newbie

                      I have done step A) by changing the property-tags: But I got an JDBCException when I run JUNIT: INFO [STDOUT] org.hibernate.exception.GenericJDBCException: could not insert: [mase.wikipage.Requirement]

                      But in the second step B), I try to remove the "blank" lines between the INSERT statements in import.sql. However I can not find the file import.sql. Where is it?

                      Thank you very much.

                      • 8. Re: Mysql
                        Imre Oßwald Newbie

                        For the examples it should be in:
                        examples/noejb/resources/
                        or
                        examples/booking/resources/

                        • 9. Re: Mysql
                          Chengyao Deng Newbie

                          Thanks for quick reply. Could you please tell me more?

                          Do you mean we should put a directory called "resources in our own ejb3 application,like helloWorld.ejb3? If so, would you please tell me where to put this "reources" dir .Is "import.sql" required to be in "resources" directory, and what content should be written in "import.sql" ?

                          From what I have understood, Jboss will create tables and insert records into tables, so why should we wirte our own?

                          Thank you very much!

                          • 10. Re: Mysql
                            Rene Lavoie Newbie

                            Import.sql just loads sample data for the booking example application.