facebook

Hibernate wizard example?

  1. MyEclipse Archived
  2.  > 
  3. Documentation
Viewing 15 posts - 1 through 15 (of 20 total)
  • Author
    Posts
  • #212449 Reply

    Stephen Smith
    Participant

    Does anyone have a brief example of how to use the Hibernate wizard in the 3.8GA version? It’s not self-obvious to me, even after attempting to read through a lot of the Hibernate ‘getting started’ docs.

    Thanks

    #212456 Reply

    Riyad Kalla
    Member

    Help > Contents, and then click on “MyEclipse Database Explorer User guide” should get you started 😉

    #212457 Reply

    Stephen Smith
    Participant

    I’m also wondering about the comment in the ‘hibernate.cfg.xml’ file which says: “Do not edit: this is a generated file that is synchonized by MyEclipse Hibernate tool integration”.

    What do you have to do to a java source file in order to get it recognized by the Hibernate integration and generate the appropriate mapping file and include it in the cfg file?

    #212461 Reply

    Riyad Kalla
    Member

    I believe the typical order of operations is a) add Hibernate caps then b) Use the DB browser to generate hibernate mappings from the tables in your DB… the tool will sync up everything for you.

    #212492 Reply

    support-jeff
    Member

    But only if you check the box to specifically update the config file. This check box is unchecked by default now; next maintenance release it will be checked by default.

    #212497 Reply

    Riyad Kalla
    Member

    Ahh good catch,thanks Jeff.

    #212631 Reply

    snpe
    Member

    Jeff,
    Why You use hibernate.cfg.xml with ddl2hbm mapping – I don’t understand ?
    If You wantt add mapping files in cfg it isn’t really important – I think that is the best use hibernate with spring and then is this unnecessery

    regards

    #213115 Reply

    support-jeff
    Member

    snpe –
    I do not follow your response:

    Why You use hibernate.cfg.xml with ddl2hbm mapping – I don’t understand ?

    We no longer use the ddl2hbm mapping tool. We use a custom Velocity based mapping tool.

    If You wantt add mapping files in cfg it isn’t really important – I think that is the best use hibernate with spring and then is this unnecessery

    It is very important to add mapping files to the config – the Hibernate Tool in ME creates a SessionFactory class for you that configures Hibernate using the XML file. You have the option of doing this manually if you wish – but you are on your own then. As for Spring support, there is the possibility that this will be added eventually (if I have anything to say about it 😉 at which point we would definitely want to support adding the mappings to the spring config file as well.

    #213932 Reply

    tarantula
    Participant

    @support-rkalla wrote:

    I believe the typical order of operations is a) add Hibernate caps then b) Use the DB browser to generate hibernate mappings from the tables in your DB… the tool will sync up everything for you.

    Hi there,

    I am using MyEclipse version 3.7.200 with Eclipse 3.0 Build 200406251208. I read the MyEclipse Database Explorer User Guide and I understand how the database explorer perspective works (eg. exporting tables via Hibernate) but I have a question about the Hibernate wizard and the order of operations you suggest.

    When I first add Hibernate capabilities to a project, I am prompted to create a new hibernate.cfg.xml file and I select the database connection I want. So far so good. I noticed there is a tab for selecting the mapping files I want to add to the hibernate.cfg.xml file but following the steps above I wouldn’t have any mapping files in my project yet.

    Also, the database explorer perspective does not allow me to export tables and create mapping files until I have added the Hibernate caps to my project. This looks like a catch-22. Do I have to add the mapping files manually to the main config file or is there another way to do this using MyEclipse?

    Thank you,
    tarantula

    #213933 Reply

    support-jeff
    Member

    No catch-22. The add mappings section of the Add Hibernate Caps/Configuration wizards is for projects that already contain mappings. Most folks creating a new project won’t have any, of course. The Export thru Hibernate feature of DB Explorer automatically will add the mappings created to the config file for you as of ME 3.8 GA – so you need to upgrade if you want this feature.

    #214478 Reply

    briani
    Member

    Is the MyEclipse´s hbm generator able to generate one-to-many relationships?

    #214495 Reply

    support-jeff
    Member

    Not yet. Just many-to-one (i.e. your typical foreign key relationship in a db). one-to-many will be coming in a future release. For now you can hack the mapping and add inverse to the many-to-one to refer to a one-to-many you can put in the related class. follow?

    #214557 Reply

    tarantula
    Participant

    Jeff,

    Thanks for the tip. I upgraded to 3.8.1 and the table-to-code generation works much better. You suggest hacking the mapping files to express different relationships (eg. one-to-many, one-to-one, etc.). Could I use XDoclet to do this?

    tarantula

    #214561 Reply

    support-jeff
    Member

    That is fine. Just be aware that (1) xdoclet is not used in the Hibernate tool to do the generation and (2) regeneration will whack your changes to the mapping and abstract base class.

    #214564 Reply

    snpe
    Member

    Jeff,
    xdoclet is used for generate mapping files (hbm) from java (not for ddl to hbm) – You can make xdoclet tags when generate java from xbm
    There is xdoclet hibernate modul

    regards

Viewing 15 posts - 1 through 15 (of 20 total)
Reply To: Hibernate wizard example?

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