facebook

How to Custom the output entity by Hibernate Reverse-Engineering

  1. MyEclipse IDE
  2.  > 
  3. Java EE Development (EJB, JSP, Struts, XDoclet, etc.)
Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #611551 Reply

    kidfruit
    Participant

    I use myeclipse hibernate reverse tool to generate entities. The problem is that if I want to custom a entity, there isn’t any template in myeclipse such as origin eclipse with JBOSS TOOLS.

    In JBOSS TOOLS, this is possible by edit template files like POJO.vm. But in myeclipse, no vm file in the same path.

    So, how to custom my entity by myeclipse?

    Best wishes!

    #611552 Reply

    Brian Fernandes
    Moderator

    Thank you for asking – you can customize these generated files, please see section 4 (and specifically 4.1) in this document https://www.genuitec.com/docs/persistence/developing-persistence-hibernate

    There is an archive of the templates that are internally used, the README file within contains additional instructions.

    Hope this helps!

    #611608 Reply

    kidfruit
    Participant

    Thanks for your help!

    The section 4.1 and 4.2 solved my problem.

    And then there is another question when I custom my strategy with code

    public class MyStrategy extends DelegatingReverseEngineeringStrategy { 
    

    public MyStrategy(ReverseEngineeringStrategy strategy){

            super(strategy); 
    

    }

     
    

    public String columnToPropertyName(TableIdentifier table, String columnName) { return “ME_” + super.columnToPropertyName(table, columnName);

    
    

    }
    `}

    Now how to debug with breakpoints. If I right click the table and click “hibernate reverse engeering” menu, it will process with “run mode” but not “debug mode”.

    • This reply was modified 5 years, 8 months ago by kidfruit.
    #611621 Reply

    kidfruit
    Participant

    After some test, more problems occur.

    When I extend DelegatingReverseEngineeringStrategy and override method, it works, but I can’t custom the annotation of entity, such as remove the ‘scheme=”xxx”‘ from @Table annotation. I test ‘tableToMetaAttributes’ method, but the result map is null.

    Then I change another way by edit templates. I found ‘ConcretePojo.vm’ in pojo folder, It has a code section like this:

    `
    #if ($clazz.table.schema)
    ,schema=”$clazz.table.schema”
    #end
    `

    After delete this code section, then do reverse engeering again, but nothing changed. It seems that the custom template can’t work as my wish.

    My myeclipse version is CI 2018.9.0, the templates you provided is for version 8.5? Is it caused by version incompatible?

    • This reply was modified 5 years, 8 months ago by kidfruit.
    #611636 Reply

    Brian Fernandes
    Moderator

    A few quick responses –

    Now how to debug with breakpoints. If I right click the table and click “hibernate reverse engeering” menu, it will process with “run mode” but not “debug mode”.

    I’m afraid debugging the reverse engineering process isn’t so straightforward. Will require MyEclipse sources, and I would not recommend trying to do this.

    As far as modifying the templates, there is no problem with the template version, that is the latest version of those files. Can you send us a screenshot of the wizard – I hope you have selected the correct folder in the RE process? Do send us the workspace error log as well – you can find this at [workspace_location]/.metadata/.log. Note that there are some cases under which the Ejb3TypeDeclaration.vm file is used, it too has the schema declaration, so do try modifying that file as well, for your testing.

    #611681 Reply

    kidfruit
    Participant

    Thanks again for your quickly reply.

    The Ejb3TypeDeclaration.vm is that I need. By edit this file it work as I wish. I used a wrong template file before.

    So, what is ConcretePojo.vm? Is there a manual to explain each .vm file and the useage of methods in these files?

    #611706 Reply

    Brian Fernandes
    Moderator

    Glad that worked. I’m afraid there isn’t detailed documentation for these files, not many users were ultimately interested in customizing reverse engineered files. You can ask here, and I will do my best to help.

    The reverse engineering wizard gives you an option to, “Create abstract class”, if this is selected, two classes will be generated for each table, one abstract class and one concrete class which extends the abstract class. The ConcretePojo.vm template is used for this concrete class.

    Hope this helps.

Viewing 7 posts - 1 through 7 (of 7 total)
Reply To: How to Custom the output entity by Hibernate Reverse-Engineering

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