Details
-
Improvement
-
Status: Closed
-
Minor
-
Resolution: Abandoned
-
1.13.0
-
None
-
None
Description
Hi Dan,
Today I came across a situation that might cause unexpected behavior, finding the real cause was not very easy because the situation showed through various errors, here some that I can remember:
- Datanucleus enhancer failed with a message that there is duplicate signature&name
- The same error as above but this time shown once the Unit-Tests started
- “Unique index or primary key violation” in a domain object which name was a duplicate
- Missing column exception
The really sad thing is that we had already two domain objects with the same name for some builds, the error messages started when I started changing one of them.
We are using autoCreateAll and are specifying table names for some classes as we are working on oracle and facing the limitation of 30 characters:
@javax.jdo.annotations.PersistenceCapable(schema = JdoConstants.A1FF_SCHEMA_NAME, table = "STEP_FIND_DSL_PORT_VULL")
@javax.jdo.annotations.Inheritance(strategy = InheritanceStrategy.NEW_TABLE)
Therefore I introduced now a test checking for this. Might this be something for Apache ISIS metamodel validation or is that more a thing for Datanucleus?
import java.util.HashSet; import java.util.Set; import javax.jdo.annotations.Inheritance; import javax.jdo.annotations.InheritanceStrategy; import javax.jdo.annotations.PersistenceCapable; import org.junit.Test; import org.reflections.Reflections; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import a1.oss.FulfillmentAppDomainModule; import static org.assertj.core.api.Assertions.assertThat; public class DuplicateDefinitionsTest { private final static Logger LOG = LoggerFactory.getLogger(DuplicateDefinitionsTest.class); @Test public void testTableNames() { HashSet<String> tableNames = new HashSet<>(); final Set<Class<?>> persistentClasses = new Reflections(FulfillmentAppDomainModule.class.getPackage().getName()) .getTypesAnnotatedWith(PersistenceCapable.class); for (Class aClass : persistentClasses) { // skip this class if it doesn't result in a separate table final Inheritance inheritance = (Inheritance) aClass.getAnnotation(Inheritance.class); if (inheritance != null && (InheritanceStrategy.SUBCLASS_TABLE.equals(inheritance.strategy()) || InheritanceStrategy.SUPERCLASS_TABLE.equals(inheritance.strategy()))) continue; String tableName = aClass.getSimpleName(); // if persistent class has annotated tablename final PersistenceCapable annotation = (PersistenceCapable) aClass.getAnnotation(PersistenceCapable.class); if (annotation != null && !annotation.table().isEmpty()) { tableName = annotation.table(); } assertThat(tableNames.add(tableName)).describedAs("Table '" + tableName + "' for class '" + aClass.getSimpleName() + "' is already used by another class") .isEqualTo(true); } assertThat(tableNames.size()).as("No persistent tables found!?").isGreaterThan(0); } }
Regards Timothy