Announcement Announcement Module
Collapse
No announcement yet.
hibernate.hbm2ddl.auto consult and doubts Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • hibernate.hbm2ddl.auto consult and doubts

    Hello guys

    Code:
    <property name="hibernateProperties">
    	<props>
           	<!-- SQL dialect -->
    	<prop key="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</prop>
     	            
    	<!-- Enable Hibernate's automatic session context management -->
    	<prop key="hibernate.current_session_context_class" >thread</prop>
    	<!-- Disable the second-level cache  -->
            <prop key="hibernate.cache.provider_class" >org.hibernate.cache.NoCacheProvider</prop>
            <!-- Echo all executed SQL to stdout -->
    	<prop key="hibernate.show_sql" >true</prop>			
    					
    	<!-- Drop and re-create the database schema on startup -->
     	<prop key="hibernate.hbm2ddl.auto" >create</prop> 
    	</props>
    </property>
    i see that each time that i startup my tomcat,
    well the db is created each time and all db data is losted

    so to avoid this,
    to before to shutdown and startup again,
    well i comment the bold line and all the db is keep it with the data

    but i am lost with this
    if i instead of create value i use
    update

    well

    1:what happens if now in my hbm files i create for the old tables more fields?
    2: i create new tables
    3: for these new tables maybe can now has relations to the old tables

    so for the old tables
    which behaviour would has this update in the schema?,
    specially with the old rows already inserted in the db?

    i am lost with this

    some advice of answers are really appreciate

    thanks in advanced

  • #2
    Any automatic changes in DB schemas outside of personal development environment are big NO-NO-NO

    Regards,
    Oleksandr

    Comment


    • #3
      Any automatic changes in DB schemas outside of personal development environment are big...
      so why the <prop key="hibernate.hbm2ddl.auto" > update option?

      regards

      Comment


      • #4
        Originally posted by dr_pompeii View Post
        so why the <prop key="hibernate.hbm2ddl.auto" > update option?

        regards
        To eveolve your schema during development. Small quotation from"Java Persistence with Hibernate" by Christian Bauer and Gavin King, chapter 2 page 64

        WARNING We've seen Hibernate users trying SchemaUpdate to update the schema of s production database automatically. This can quickly end in disaster and won't be allowed by your DBA.
        To make things clear - SchemaUpdate tool is tool activated by hbm2ddl.auto=true.

        Regards,
        Oleksandr

        Comment


        • #5
          Hello

          thanks for the reply,

          wondered why this dangerous option is available is has a high risk to kill the db

          regards

          Comment


          • #6
            Originally posted by dr_pompeii View Post
            Hello

            thanks for the reply,

            wondered why this dangerous option is available is has a high risk to kill the db

            regards
            It is convinient (or at least may be convinient) during development, BTW, the whole HibernateTools package is development, not production oriented. Any decent database (I mean DB size) needs a lot of manual schema tuning to optimize performance which is DB-specific and can not be done with this tool.

            There is another reason (IMHO) the whole phylosophy of Hibernate is to provide a user with any and all imaginable options and allow him to select what suits him more. The whole book that I have mentioned is ovecrowded with statements like "Hibernate supports option XXX, but we do not reccomend to use it".

            Regards,
            Oleksandr

            Comment


            • #7
              It is convinient (or at least may be convinient) during development, BTW, the whole HibernateTools package is development, not production oriented.
              sad to read that

              The whole book that I have mentioned is ovecrowded with statements like "Hibernate supports option XXX, but we do not reccomend to use it".
              really wondered

              well, i have this situation,
              my system are in a 95% to finish and my boss want all the system working,
              i told him about that if he want a new requeriments maybe can happens one of the 3 options already written

              Code:
              1:what happens if now in my hbm files i create for the old tables more fields?
              2: i create new tables
              3: for these new tables maybe can now has relations to the old tables
              so now friend,
              you told me that hibernate cant does this job,
              what reasonable options i have for this situation?

              regards and thanks in advanced

              Comment


              • #8
                Why, Hibernate can, just do not do it on production.

                Write the new/update old files, generate scripts to update database schema with hbm2ddl.update by redirecting output to the file (it is described in the Hibernate reference, 20.1.5, 20.1.6), test them throughfully and only then apply to the production DB. Just few more step involved.

                BTW, I myself do not use automatic generation tools and always write DB scripts manually, but I do not use Hibernate so much anyway.


                Regards,
                Oleksandr

                Originally posted by dr_pompeii View Post
                sad to read that


                really wondered

                well, i have this situation,
                my system are in a 95% to finish and my boss want all the system working,
                i told him about that if he want a new requeriments maybe can happens one of the 3 options already written

                Code:
                1:what happens if now in my hbm files i create for the old tables more fields?
                2: i create new tables
                3: for these new tables maybe can now has relations to the old tables
                so now friend,
                you told me that hibernate cant does this job,
                what reasonable options i have for this situation?

                regards and thanks in advanced

                Comment


                • #9
                  Why, Hibernate can, just do not do it on production.
                  thats the problem the boss want the system to enter to production in a 95% and i am afraid to listen, "i want this....." and change the db schema

                  Write the new/update old files, generate scripts to update database schema with hbm2ddl.update by redirecting output to the file (it is described in the Hibernate reference, 20.1.5, 20.1.6), test them throughfully and only then apply to the production DB. Just few more step involved.
                  i will read carefully that, coz i dont how do that ,thanks for the tip

                  BTW, I myself do not use automatic generation tools and always write DB scripts manually,
                  so you dont use your hbm mapping files to create the tables?

                  wooh, how you manage at least 50 tables with 20 fields ? manually?

                  regards and thanks for your time

                  Comment


                  • #10
                    There are DB designer tools that like ErWin or PowerDesigner that can (and should) be used to design db schemas. Anything else will, on any project of a decent size, sooner or later, end up as another IT disaster.

                    Comment


                    • #11
                      There are DB designer tools that like ErWin or PowerDesigner that can (and should) be used to design db schemas.
                      always i use the hbm files, the class diagram normally with hibernate should be the same
                      that ER for he DB

                      regards

                      Comment


                      • #12
                        Originally posted by dr_pompeii View Post
                        thats the problem the boss want the system to enter to production in a 95% and i am afraid to listen, "i want this....." and change the db schema


                        i will read carefully that, coz i dont how do that ,thanks for the tip


                        so you dont use your hbm mapping files to create the tables?

                        wooh, how you manage at least 50 tables with 20 fields ? manually?

                        regards and thanks for your time
                        Never was in position to do it - never have used Hibernate for such kind of applications. The biggest application that I have done with Hibernate had about 10 tables (w/o Hibernate - about 300 tables ).

                        First of all, I woul rather start from DB tables, then Java objects and only then - mappings. But in any case I would use a tool only for initial generation and not for the evolution (except validation mode of hbm2ddl).

                        Do not forget that data in DB have tendencies to outlive any given application (if not technology) and to be shared with many ones (even if it was not initially supposed). So DB data structures is of utmost importancy.

                        Regards,
                        Oleksandr

                        Comment


                        • #13
                          Originally posted by dejanp View Post
                          There are DB designer tools that like ErWin or PowerDesigner that can (and should) be used to design db schemas. Anything else will, on any project of a decent size, sooner or later, end up as another IT disaster.
                          For me nothing is more clear and convinient as good old plain SQL scripts (with decent comments). Tools mentioned do not give clear overviewof any DB with more then, dare to say, 100 objects. Diagrams becomes ovecrowded and/or clottered.

                          Comment


                          • #14
                            The biggest application that I have done with Hibernate had about 10 tables (w/o Hibernate - about 300 tables ).
                            pretty number

                            First of all, I woul rather start from DB tables, then Java objects and only then - mappings.
                            right order, same approach i do

                            Do not forget that data in DB have tendencies to outlive any given application (if not technology) and to be shared with many ones (even if it was not initially supposed). So DB data structures is of utmost importancy.
                            thats right, the baseline of the rest of the layers

                            For me nothing is more clear and convinient as good old plain SQL scripts (with decent comments). Tools mentioned do not give clear overviewof any DB with more then, dare to say, 100 objects. Diagrams becomes ovecrowded and/or clottered.
                            lower programming is powerful always, Erwin for few tables is nice, but for a lot
                            is a wonderful hell



                            regards

                            Comment


                            • #15
                              Originally posted by al0 View Post
                              For me nothing is more clear and convinient as good old plain SQL scripts (with decent comments). Tools mentioned do not give clear overviewof any DB with more then, dare to say, 100 objects. Diagrams becomes ovecrowded and/or clottered.
                              For you perhaps, but you are not writing the application and documentation for yourself.

                              You should have many diagrams, showing different facets of the schema. One diagram representing all the tables of a non-trivial system is as usefull as reading a telephone book from cover to cover.

                              Comment

                              Working...
                              X