facebook

SchemaExportTask

  1. MyEclipse Archived
  2.  > 
  3. Database Tools (DB Explorer, Hibernate, etc.)
Viewing 13 posts - 1 through 13 (of 13 total)
  • Author
    Posts
  • #250129 Reply

    macinsmith
    Member

    One of the great features of Hibernate is it’s ability to generate both the POJO and the schema from the mapping file. Is there any word on when you plan to incorporate the functionality of SchemaExportTask into MyEclipse? The Ant build file and and the mapping files are in the example code for Oreilly’s book Hibernate:Developer’s Notebook at <http://examples.oreilly.com/hibernate/SourceExamples.zip&gt; If you use the Chapter 9 code and run the schema target, it will generate the schema.

    Stephen Smith

    #250144 Reply

    Haris Peco
    Member

    Stephen,

    We know for hibernate schema export and think about this feature.Problem is that hibernate schema export tool isn’t too good and you have to define table/column properties in mapping file (column and meta element) – it is easier define table with our table edit wizards (in future releases) and make mapping files and POJO with our reverse engineering tool – however,we will probably add schema export tool for cases when users have mapping files already.

    Thanks

    #250155 Reply

    macinsmith
    Member

    Hi,

    Thank you for your response. I don’t mean to be argumentative. Yes, your table edit wizard is probably easier to use, but there is a real advantage in starting with the mapping files and generating the schema and the POJO. That way everything is in one place, and there is no problem with getting them out of sync with each other. It also is better for automated testing since you can discard the database and have it created, populate it and run your tests against a known environment. I believe that both tools are necessary. I realize that I can use Ant with Eclipse and still use these tools as an alternative.

    Stephen Smith

    #250542 Reply

    antoine
    Member

    My point on the subject is that the table wizard doesn’t answer to all the needs. It supposes that you start your project from the database schema and on some project that’s a rather complex start.
    My current project would have been very hard to design from the database. I have to adapt a bunch (20 or so) of paper form in a web app. Those forms have a lot of common fields and some particular fields. They also have “list” parts (list of authors, list of file resources, etc…). So I started my project from the beans : a class hierarchy of 20 members and few partner classes : File Resources and so. Stuck in Java 1.4 I used Xdoclet to integrate hibernate tags in my source(BTW xdoclet Hibernate configuration files are buggy : I had to make some correction to get my “one-to-many” mappings work. If someone needs them I can send those corrections) and used schemaExportTask to generate database table from may mmapping files. It works and is very powerful.
    Most of my hibernate xdoclet tags looks like this :

    /**
         * @hibernate.property 
         */
         public String getMisc()
         {
         ...

    Xdoclet generates a maping entry like this

    <property
                name="misc"
                type="java.lang.String"
                column="misc"
            />

    As you see Xdoclet use the name of the bean field for the column name. If I needed another name I had to add information in the Xdoclet tag.
    I also have more complex Hibernate Xdoclet tag like his :

      /*
       * @hibernate.list
         * cascade="all"
         * lazy="false"
         * @hibernate.collection-key 
         * column="PUBID"
         * not-null="true"
         * @hibernate.collection-index 
         * column="ind"
         * @hibernate.collection-one-to-many  
         * class="cv.prof.domain.Resource"
         * 
         */
        
        public List getResources()
        {
        ...
    

    Xdoclet generates the one to many maping without any problem

    <list
                name="resources"
                lazy="false"
                cascade="all"
            >
    
                <key
                    column="PUBID"
                      not-null="true"
                >
                </key>
    
                <index
                    column="ind"
                />
    
                <one-to-many
                      class="cv.prof.domain.Resource"
                />
    
            </list>

    As the cv.prof.domain.Resource has also a maping I have my relational model built automatically.
    Using SchemaExportTask is rather easy. I had to add hibernate.jar and some dependencies in the class path of my build.xml ant file. After that I add a new target to my ant file :

    
        <target name="schemaExport4Mysql">
                <taskdef name="schemaexport" 
            classname="org.hibernate.tool.hbm2ddl.SchemaExportTask"
    
            />
            <schemaexport
                properties="hibmysql.properties"
            quiet="no"
            text="yes"
                delimiter=";"
                output="schema-mysql.sql"
                >
                
                <fileset dir="src">
                    <include name="**/*.hbm.xml"/>
        </fileset>
                </schemaexport>
    
            
            </target>

    This generates me a rather complex sql file with all my varchar defaulted to 255 size as I didn’t specify length in my Xdcolet tags (I could have precise them if I needed to). I also got all my foreign key and integrity constraints build for me.
    Et voila !

    All I need now is a tool to build a simple JSP, Struts or JSF form from my bean and I’ll have all the tools to generate code from UI to database from one file. The RAD paradise is not very far :-).

    Antoine

    #250543 Reply

    antoine
    Member

    In my previous post I didn’t mention schemaUpdateTask to keep all the stuff synchronized. As you change your beans you can use this hibernate tool to update your schema.
    Antoine

    #250551 Reply

    macinsmith
    Member

    Antoine,

    I would be interested if you posted your fixes. I’ve had trouble getting my java.util.collections to map correctly and have not tried using xdoclet.

    You chose to start with you application, and in many cases I believe that is the right place to start. There are times in which one knows the information that must be persisted and can start with the schema. There are times in which the schema is defined and we have to start from it. Then there are times in which we want to examine and modify our schema using a GUI. That’s why we need different tools. The beauty of Hibernate, tools like xdoclet and plugins like MyEclipse with it’s GUI are that one can pick the right tool for the job. My point to the MyEclipse group is that SchemaExportTask needs to be a part of their plugin, and you might argue that xdoclet also needs to be a part and I would agree.

    Thanks for your input.

    Stephen Smith

    #250615 Reply

    antoine
    Member

    Stephen,

    I totally agree with you. Both approach are valid.
    For me, starting from datamodel is not natural, but I understand that other people can see things differently or that you need to start from it in certain case (although I think that iBatis is better when you have to deal with a legacy data model). Beside as I’m not SQL specialist, automated tools from hibernate generate better sql than I can.
    Concerning Xdoclet the distribution contains big bugs concerning hibernate and so the jboss plugin used by my eclipse do. I made some corrections in some configuration files of the plugin (I sent you those files) and it works for my needs. When I’ll be abble to use java 5 on my projects I’ll be happy to leave xdoclet for annotations :-).

    Antoine

    #250630 Reply

    macinsmith
    Member

    Thanks

    #250688 Reply

    rtrask
    Member

    I too like the approach of having a mapping file, ant agile, test-driven approach as recommended in the O’Reilly Hibernate A Developer’s Notebook. What is the recommended approach to best leverage MyEclipse? Or do I just use the hibernate tools from hibernate.org and Ant.

    BTW – I also intend to use spring.

    Thx,
    Ray

    #250689 Reply

    macinsmith
    Member

    I highly recommend Oreilly’s Hibernate: Developer’s Notebook. I went through the book using ant, then tried to work through it under Eclipse and found that there were some parts missing. First, the GeneratePOJO had a couple of flaws that the developers at MyEclipse have acknowledged and plan to fix. Then I found that there was no SchemaExportTask which is what prompted this thread. So for now, you will have to use an Ant build from within Eclipse to generate the schema.

    Stephen Smith

    #250693 Reply

    antoine
    Member

    I’m using Spring with all the stuff I mentioned above. In this process the tools from MyEclipse I use are Spring and Xdoclet integration. For the end of the process I use Ant and hibernate tools. I’m not really missing Myeclipse integration of schemaexport, since I don’t see what they could do more for this except perhaps maintain Spring configuration file when an Hibernate mapping file is created.

    Antoine

    #250706 Reply

    rtrask
    Member

    Thanks for the inputs Stephen & Antoine, ANT it is!!!

    #250740 Reply

    Brian Fernandes
    Moderator

    Guys,

    What snpe intended to say above is that the Schema generation tools shipped by Hibernate are not perfect and sub-optimal DDL might result. Having said that, it might very well be good enough for your use and a little tweaking might be necessary, but this still puts it ahead of writing up schemas manually for a large number of tables. So we are definitely looking at adding some sort Schema generation capability shortly. We appreciate all the feedback on this thread 🙂

    Stephen, the POJO generation errors have been fixed and will be available in 5.0M1 – thank you for reporting the issue.

    Best,
    Brian.

Viewing 13 posts - 1 through 13 (of 13 total)
Reply To: SchemaExportTask

You must be logged in to post in the forum log in