1 2 Previous Next 23 Replies Latest reply on Feb 12, 2009 1:13 AM by tony.herstell1

    Easy Question about Length

    tony.herstell1


      @NotNull(message="required")
      @Column(length=1500)
      private String description;
      



      Gives


      description;VARCHAR;255;;;NO;NO;;
      



      I am trying to set a column to a length of 1500, but I have tried various annotations to no avail... All I want is the varchar to be 1500!


      MySQL version is latest Prod (so should be allowed).


      No errors in startup script!


      Is this a bug?

        • 1. Re: Easy Question about Length
          swd847

          Which MySql hibernate dialect are you using? There should be a line on server startup that tells you, on mine it looks like:



          16:08:56,576 INFO  [Dialect] Using dialect: org.hibernate.dialect.PostgreSQLDialect




          I think the dialect that you want to use is org.hibernate.dialect.MySQL5Dialect, not org.hibernate.dialect.MySQLDialect

          • 2. Re: Easy Question about Length
            tony.herstell1

            I am using


            <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLInnoDBDialect"/>
            



            There does not seem to be a 5 version of this...


            see Hibernate Dialect

            • 3. Re: Easy Question about Length
              tony.herstell1

              I am pretty sure I had to do this for some reason but can't remember why now! was a couple of years ago I set this up!



              I THINK the below config sets me up to use Seam Based Tansactions which I needed to happen to use some RichFaces components.



              <?xml version="1.0" encoding="UTF-8"?>
              <persistence xmlns="http://java.sun.com/xml/ns/persistence" 
                           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                           xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" 
                           version="1.0">
                 <persistence-unit name="secDatabase">
                    <provider>org.hibernate.ejb.HibernatePersistence</provider>
                    <jta-data-source>java:/secDatasource</jta-data-source>
                    <properties>
                        <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLInnoDBDialect"/>
                       <property name="hibernate.hbm2ddl.auto" value="update"/>
                       <property name="hibernate.show_sql" value="true"/>
                       <!-- These are the default for JBoss EJB3, but not for HEM: -->
                       <property name="hibernate.cache.provider_class" value="org.hibernate.cache.HashtableCacheProvider"/>
                       <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup"/>
                       <property name="jboss.entity.manager.factory.jndi.name" value="java:/secEntityManagerFactories"/>
                    </properties>
                 </persistence-unit>
              </persistence>





              <?xml version="1.0" encoding="UTF-8"?>
              
              <datasources>
                   <local-tx-datasource>
                        <jndi-name>secDatasource</jndi-name>
                        <connection-url>
                             jdbc:mysql://localhost:3306/selwyn
                        </connection-url>
                        <driver-class>com.mysql.jdbc.Driver</driver-class>
                        <user-name>root</user-name>
                        <password>xxxxxxx</password>
                   </local-tx-datasource>
              </datasources>




                   <persistence:managed-persistence-context name="entityManager" auto-create="true"
                        persistence-unit-jndi-name="java:/secEntityManagerFactories"/>




              • 4. Re: Easy Question about Length
                swd847

                Try using org.hibernate.dialect.MySQL5InnoDBDialect. This dialect defiantly exists, if you do not have it upgrade your hibernate or get the dialect from the latest hibernate sources and package it with your app.

                • 5. Re: Easy Question about Length
                  tony.herstell1

                  No error reported when using


                  <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect"/>



                  Seems to exist!


                  However, still has not changed the column size to 1500...


                  :(



                  19:21:13,765 INFO  [Server] Starting JBoss (MX MicroKernel)...
                  19:21:13,765 INFO  [Server] Release ID: JBoss [Trinity] 4.2.1.GA (build: SVNTag=JBoss_4_2_1_GA date=200707131605)
                  19:21:13,765 INFO  [Server] Home Dir: C:\jboss-4.2.1.GA
                  19:21:13,765 INFO  [Server] Home URL: file:/C:/jboss-4.2.1.GA/
                  19:21:13,765 INFO  [Server] Patch URL: null



                  19:21:32,906 INFO  [Version] Hibernate EntityManager 3.2.1.GA
                  19:21:32,937 INFO  [Version] Hibernate Annotations 3.2.1.GA
                  19:21:32,937 INFO  [Environment] Hibernate 3.2.4.sp1
                  19:21:32,953 INFO  [Environment] hibernate.properties not found
                  19:21:32,953 INFO  [Environment] Bytecode provider name : javassist
                  19:21:32,953 INFO  [Environment] using JDK 1.4 java.sql.Timestamp handling



                  19:21:34,703 INFO  [SettingsFactory] RDBMS: MySQL, version: 5.1.30-community
                  19:21:34,703 INFO  [SettingsFactory] JDBC driver: MySQL-AB JDBC Driver, version: mysql-connector-java-5.1.7 ( Revision: ${svn.Revision} )
                  19:21:34,734 INFO  [Dialect] Using dialect: org.hibernate.dialect.MySQL5InnoDBDialect
                  19:21:34,734 INFO  [TransactionFactoryFactory] Transaction strategy: org.hibernate.ejb.transaction.JoinableCMTTransactionFactory






                  Also, how do I get this set to true?


                  19:21:34,750 INFO  [SettingsFactory] Generate SQL with comments: disabled



                  as I have this:


                  <property name="hibernate.show_sql" value="true"/>



                  • 6. Re: Easy Question about Length
                    jharting

                    <property name="hibernate.use_sql_comments" value="true"/>


                    http://www.hibernate.org/hib_docs/reference/en/html/configuration-optional.html

                    • 7. Re: Easy Question about Length
                      tony.herstell1

                      Still cant get the column to 1500.


                      Any more ideas?

                      • 8. Re: Easy Question about Length
                        tony.herstell1

                        As annotating the Entity does not work is there any way to hack the database?

                        • 9. Re: Easy Question about Length
                          swd847

                          Are you trying to update an existing database or are you having hibernate create all the tables each time? If you are updating it each time you can change the column length manually using 'ALTER TABLE'.


                          If you are creating the tables afresh each time and it is still not working, put the ALTER TABLE stamement in a file called import.sql and put it in the root of the classpath of the jar that contains the entity manager. Whenever hibernate creates the new schema it should execute the SQL in this file. 

                          • 10. Re: Easy Question about Length
                            tony.herstell1

                            Its a live system for on-line entering of our equestrian events.


                            So what you are saying is that I can use AlterTable and the next re-start of the server wont re-set them...


                            If

                            it doesnt re-set the length then that would explain why its not setting them to 1500 as expected as usually any changes to the Entity cause the Alter table to fire (leaving behind unused columns which sort of makes sense as they may still contain data) so why would setting the length NOT follow this pattern?


                            Anyhow; will give it a try tonight.


                            (interesting bug in seam text that if you use the bold tags round a piece of text if forces a new line ... and I was blaming RF guys for it  - oops!)


                            • 11. Re: Easy Question about Length
                              swd847

                              I just has a look at the hbm2ddl code and it looks like hibernate will not update the type, you are going to have to do it manually. The code is in org.hibernate.mapping.Table#sqlAlterStrings if you want to have a look for yourself.

                              • 12. Re: Easy Question about Length
                                tony.herstell1

                                Darn I have to learn some more SQL!
                                humm..
                                Alter Table... google goolge...


                                Sounds doable... Get so used to Seam/Hibernate doing it all for me.


                                Look at Hibernate code.. err... I'll add to list.


                                Thanks.

                                • 13. Re: Easy Question about Length
                                  tony.herstell1

                                  I did this but when I restarted the App Server (Jboss) it resets the length to 255 (regardless of the @Length annotation).


                                  Any ideas?

                                  • 14. Re: Easy Question about Length
                                    sander

                                    http://dev.mysql.com/doc/refman/5.0/en/char.html


                                    In the older versions a varchar is max 255 so think hibernate is just not up to date. If you want to get more text into a varchar make it a text field by annotating it with @lob (think that is right annotation otherwist look for it)


                                    Just wondering why you want a mysql varchar(1500) and not a text field, those are ment for lots of text .. ?

                                    1 2 Previous Next