[FIX] @ManyToMany auto link generation

Not functionnal di to the bijectivity model ==> need fix it
This commit is contained in:
Edouard DUPIN 2025-04-18 08:14:36 +02:00
parent 8a9567d730
commit 106e64a90c

View File

@ -120,7 +120,8 @@ public class AddOnManyToMany implements DataAccessAddOn {
public record LinkTableWithMode( public record LinkTableWithMode(
String tableName, String tableName,
boolean first) {} boolean first,
boolean equals) {}
public static LinkTableWithMode generateLinkTableNameField( public static LinkTableWithMode generateLinkTableNameField(
final String tableName, final String tableName,
@ -134,14 +135,16 @@ public class AddOnManyToMany implements DataAccessAddOn {
final String tableAFieldName, final String tableAFieldName,
final String tableBName, final String tableBName,
final String tableBFieldName) { final String tableBFieldName) {
if (tableAName.compareTo(tableBName) < 0) { final String concatElementA = tableAName + "_" + tableAFieldName;
return new LinkTableWithMode( final String concatElementB = tableBName + "_" + tableBFieldName;
hashIfNeeded(tableAName + "_" + tableAFieldName + "_link_" + tableBName + "_" + tableBFieldName), final int compareResult = concatElementA.compareTo(concatElementB);
true); if (compareResult == 0) {
return new LinkTableWithMode(hashIfNeeded(concatElementA + "_autolink"), true, true);
} }
return new LinkTableWithMode( if (compareResult < 0) {
hashIfNeeded(tableBName + "_" + tableBFieldName + "_link_" + tableAName + "_" + tableAFieldName), return new LinkTableWithMode(hashIfNeeded(concatElementA + "_link_" + concatElementB), true, false);
false); }
return new LinkTableWithMode(hashIfNeeded(concatElementB + "_link_" + concatElementA), false, false);
} }
public static LinkTableWithMode generateLinkTableName( public static LinkTableWithMode generateLinkTableName(
@ -525,7 +528,6 @@ public class AddOnManyToMany implements DataAccessAddOn {
} else { } else {
throw new DataAccessException("DataAccess Not managed"); throw new DataAccessException("DataAccess Not managed");
} }
} }
public static long removeLink( public static long removeLink(
@ -550,6 +552,8 @@ public class AddOnManyToMany implements DataAccessAddOn {
} }
} }
private static List<String> tableAlreadyCreated = new ArrayList<>();
@Override @Override
public void createTables( public void createTables(
final String tableName, final String tableName,
@ -567,7 +571,7 @@ public class AddOnManyToMany implements DataAccessAddOn {
throw new SystemException("MappedBy must be set in ManyMany: " + tableName + " " + field.getName()); throw new SystemException("MappedBy must be set in ManyMany: " + tableName + " " + field.getName());
} }
final LinkTableWithMode linkTable = generateLinkTableNameField(tableName, field, options); final LinkTableWithMode linkTable = generateLinkTableNameField(tableName, field, options);
if (linkTable.first()) { if (linkTable.first() || linkTable.equals()) {
final QueryOptions options2 = new QueryOptions(new OverrideTableName(linkTable.tableName())); final QueryOptions options2 = new QueryOptions(new OverrideTableName(linkTable.tableName()));
final Class<?> objectClass = (Class<?>) ((ParameterizedType) field.getGenericType()) final Class<?> objectClass = (Class<?>) ((ParameterizedType) field.getGenericType())
.getActualTypeArguments()[0]; .getActualTypeArguments()[0];