facebook

Hibernate foreign keys mapping wrong getters and setters

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

    zoked
    Member

    Hey devangv ,

    that’s the solution!
    So the whole problem seems not to be a MyEclipse or hibernate issue.

    Getting rid of single letters in between ‘_’ in database table names and remappingmadethe wholething work very well.

    Appologizes for bothering and many thanks for taking care to all of you!

    Great!

    #243726 Reply

    ramanurs
    Member

    Hi zoked – It was really nice of you to add this one. I was struggling with this from past one week.

    Thanks,
    Ram

    #309414 Reply

    Nigel Schoon
    Participant

    Hi

    Please confirm – have I come across the same error???
    My first time following Hibernate tutorials, and I have a table in MySQL with fields such as 01_title 02_intro etc, (all are two digits underscore word).

    After Hibernate reverse engineering, in the file tablenameDAO.java there are countless errors:

    eg

    public class BookDAO extends BaseHibernateDAO {
    private static final Logger log = LoggerFactory.getLogger(BookDAO.class);
    //property constants
    public static final String 01_TITLE = “01Title”;
    public static final String 02_INTRO = “02Intro”;
    etc

    Do I need to to change the table names and start over?
    thank you
    Nigel

    #309434 Reply

    Ram
    Member

    Nigel_VS,

    According to Java language,the names of variables should not start with digit,which is happening in your case.
    I would recommend you to use a custom reverse engineering strategy(Refer http://www.myeclipseide.com/documentation/quickstarts/hibernate/#5-6).

    Steps to follow:
    ============
    1. Add the MyEclipse Persistence Tools library to your project.

      * Right click your project and select Properties.
      * On the Java Build Path page, choose Add Library… on the Libraries tab.
      * Choose MyEclipse Libraries and then MyEclipse Persistence Tools.
      * Press Finish.

    2. Create a new class in your project which extends the org.hibernate.cfg.reveng.DelegatingReverseEngineeringStrategy class.
    3. Define the single argument constructor and override a method of interest, for example, columnToPropertyName.
    Here’s an example which prefixes all generated propertes with “ME_”
    MyStrategy.java
    package com.genuitec.hibernate;

    import org.hibernate.cfg.reveng.DelegatingReverseEngineeringStrategy;
    import org.hibernate.cfg.reveng.ReverseEngineeringStrategy;
    import org.hibernate.cfg.reveng.TableIdentifier;

    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 while Reverse Engineering again on your table,you need to refer the above created class(MyStrategy.java) in “Custom rev_eng strategy” field in the 2nd wizard of Reverse Engineer .

    Let me know how this works for you.

Viewing 4 posts - 16 through 19 (of 19 total)
Reply To: Hibernate foreign keys mapping wrong getters and setters

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