@@ -43,27 +43,28 @@ public static void generateMappings(final Table table) {
4343 Table table1 = tablesMap .get (foreignKeyConstraintList .get (0 ).getReferencedTableName ());
4444 Table table2 = tablesMap .get (foreignKeyConstraintList .get (1 ).getReferencedTableName ());
4545
46+ //Adding @ManyToMany and @JoinTable to table1
4647 Column column1 = new Column ();
47- column1 .setFieldName (table2 . getClassName (). toLowerCase ( ));
48+ column1 .setFieldName (CaseUtils . toCamelCase ( table2 . getName (), false , '_' ));
4849 column1 .setType (table2 .getClassName ());
4950 column1 .getAnnotations ().add (ManyToManyAnnotation .builder ().build ().toString ());
50-
5151 Set <JoinColumnAnnotation > joinColumnAnnotations = new HashSet <>();
5252 for (String column : foreignKeyConstraintList .get (0 ).getColumns ()) {
5353 joinColumnAnnotations .add (JoinColumnAnnotation .builder ().name (column ).build ());
5454 }
55-
5655 Set <JoinColumnAnnotation > joinInverseColumnAnnotations = new HashSet <>();
5756 for (String column : foreignKeyConstraintList .get (1 ).getColumns ()) {
5857 joinInverseColumnAnnotations .add (JoinColumnAnnotation .builder ().name (column ).build ());
5958 }
60-
6159 column1 .getAnnotations ().add (JoinTableAnnotation .builder ().tableName (table .getName ()).joinColumns (joinColumnAnnotations ).inverseJoinColumns (joinInverseColumnAnnotations ).build ().toString ());
60+ table1 .getColumns ().add (column1 );
6261
62+ //Adding @ManyToMany(mappedBy) to table2
6363 Column column2 = new Column ();
64- column2 .setFieldName (table1 . getClassName (). toLowerCase ( ));
64+ column2 .setFieldName (CaseUtils . toCamelCase ( table1 . getName (), false , '_' ));
6565 column2 .setType (table1 .getClassName ());
66- column2 .getAnnotations ().add (ManyToManyAnnotation .builder ().mappedBy (column1 .getFieldName ()).toString ());
66+ column2 .getAnnotations ().add (ManyToManyAnnotation .builder ().mappedBy (column1 .getFieldName ()).build ().toString ());
67+ table2 .getColumns ().add (column2 );
6768
6869 } else {
6970 //Case1: There are some fields that are not foreign keys. So separate entity is needed to track Link Table
@@ -80,13 +81,13 @@ public static void generateMappings(final Table table) {
8081 private static void addBothUnidirectionalMappings (Table table , ForeignKeyConstraint foreignKeyConstraint ) {
8182 Table referencedTable = tablesMap .get (foreignKeyConstraint .getReferencedTableName ());
8283 Column foreignKeyColumn = new Column ();
83- foreignKeyColumn .setFieldName (referencedTable . getClassName (). toLowerCase ( ));
84+ foreignKeyColumn .setFieldName (CaseUtils . toCamelCase ( referencedTable . getName (), false , '_' ));
8485 foreignKeyColumn .setType (referencedTable .getClassName ());
8586 foreignKeyColumn .getAnnotations ().add (new ManyToOneAnnotation ().toString ());
8687 table .getColumns ().add (foreignKeyColumn );
8788
8889 Column childKeyColumn = new Column ();
89- childKeyColumn .setFieldName (table . getClassName (). toLowerCase ( ));
90+ childKeyColumn .setFieldName (CaseUtils . toCamelCase ( table . getName (), false , '_' ));
9091 childKeyColumn .setType ("Set<" + table .getClassName () + ">" );
9192 childKeyColumn .getAnnotations ().add (OneToManyAnnotation .builder ().mappedBy (foreignKeyColumn .getFieldName ()).build ().toString ());
9293 referencedTable .getColumns ().add (childKeyColumn );
0 commit comments