1 2 Previous Next 23 Replies Latest reply on Feb 12, 2009 1:13 AM by tony.herstell1 Go to original post
      • 15. Re: Easy Question about Length
        tony.herstell1

        I didn't really care what Hibernate used... I just annotated the Entity and trusted Hibernate to look after the Database on the premise that it knows best (as it is written by experts!).


        Hence...


        @Column(length=2500)
        private String sponsorDescription;




        The Manifest for the Hiberante Library I have installed is


        Manifest-Version: 1.0
        Ant-Version: Apache Ant 1.6.5
        Created-By: 1.4.2_11-b06 (Sun Microsystems Inc.)
        Implementation-Title: Hibernate3
        Implementation-Version: 3.2.4.sp1
        Implementation-Vendor: hibernate.org
        Hibernate-Version: 3.2.4.sp1



        which appears to be what was supplied with Seam 2.1.1.GA


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

          Is there any point asking this on Hibernate forums?



          I have a site live and need to add in WAY more than the 255 characters its allowing me to add!

          • 17. Re: Easy Question about Length
            swd847

            Hibernate defiantly supports it, in the Mysql5 Dialect:



            protected void registerVarcharTypes() {
                            registerColumnType( Types.VARCHAR, "longtext" );
                            registerColumnType( Types.VARCHAR, 16777215, "mediumtext" );
                            registerColumnType( Types.VARCHAR, 65535, "varchar($l)" );
                    }
            



            which overrides the Basic Mysql Dialect:



            protected void registerVarcharTypes() {
                            registerColumnType( Types.VARCHAR, "longtext" );
                            registerColumnType( Types.VARCHAR, 16777215, "mediumtext" );
                            registerColumnType( Types.VARCHAR, 65535, "text" );
                            registerColumnType( Types.VARCHAR, 255, "varchar($l)" );
                    }
            




            If you change <property name=hibernate.hbm2ddl.auto value=update/>
            to 'validate' and manually run your alter table statement what happens? (automatic schema generation is not recommended on a production system anyway...).



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

              Thanks Stuart,


              I will try this when I get home.


              Since 255 is not even in the new dialect then why would re-starting the server change it to 255? Perhaps I will have to go look in some code!


              Very curious all this...

              • 19. Re: Easy Question about Length
                swd847

                255 is the default length for text columns, but weather thats related or not I couldn't say.

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

                  Success


                  Ignore the @Length annotation and use the @Column annotation


                  This way you can set the column names and they don't get changed back.


                  Probably not right, but it works and setting validate causes no errors.

                  • 21. Re: Easy Question about Length
                    swd847

                    @Length is a hibernate validator annotation. Try leaving @Length but setting hibernate.validator.applytoddl to false.

                    • 22. Re: Easy Question about Length
                      swd847

                      Sorry, that should have been hibernate.validator.apply_to_ddl

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

                        I looked up


                        hibernate.validator.apply_to_ddl



                        and this will stop the forced creation of the tables/columns/attributes that map to my entities annotations.


                        hib manual


                        Since I only use Hib to create/update my tables using Create and then Update on the hibernate.hbm2ddl.auto param I am sersiouly loath to do this as I am SURE that Hibernate can do a better job of deciding what my Database should look like (including column types etc.) than me!


                        I also would like to have @Length working if it is an Annotation that bubbles up through seam to my screens! so its a real shame that it forces the varchars to an odd length.


                        Thanks for you help though.


                        MUCH appreciated.


                        1 2 Previous Next