Sleep Continuity

I have

  • The MySQL database currently used for use in the CakePHP application
  • A Java SE application accessing the same database through Hibernate is currently under development.

I use the "automate" function of Netbeans to create POJO classes and XML files (do I really need XML files when using annotations?). Because the layout is quite complex, manually creating tables is too much work.

Cake expects all database tables to be multiple (the Address class is automatically mapped to an address table). When Netbeans automatic migration starts, it pluralizes the names of already pluralized tables (I get the Addresses.java and setAddresseses () methods).

I know that I am asking for problems with running two very different data layers in relation to the same database, but I would like to know if Netbeans can generate POJO classes in a single form or if there is another (better) way to manage this.

+3
source share
1 answer

For reverse engineering, you can use a custom reverse engineering strategy . Indication of documentation:

. org.hibernate.cfg.reveng.ReverseEngineeringStrategy. DelegatingReverseEngineeringStrategy , ReverseEngineeringStrategy as . . , , "PK" "id".

public class ExampleStrategy extends DelegatingReverseEngineeringStrategy {
    public ExampleStrategy(ReverseEngineeringStrategy delegate) {
        super(delegate);
    }
    public String columnToPropertyName(TableIdentifier table, String column) {
        if(column.endsWith("PK")) {
            return "id";
        } else {
            return super.columnToPropertyName(table, column);
        }
    }
}

public String tableToClassName(TableIdentifier tableIdentifier) {
    return delegate==null?null:delegate.tableToClassName(tableIdentifier);
}

"" , (ADDRESSES = > Address).

, , NetBeans Hibernate Reverse Engineering Wizard , - ( , NetBeans 7.0, ).

, , Ant Maven. NetBeans.

+2

Source: https://habr.com/ru/post/1733041/


All Articles