Skip to content

Commit

Permalink
Fixed duplicate entity #258
Browse files Browse the repository at this point in the history
  • Loading branch information
beikov committed Sep 29, 2016
1 parent 59ab305 commit e849496
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@ public Class getServiceInitiated() {

@Override
public void integrate(Configuration configuration, SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry) {
Class<?> valuesEntity;
boolean registerValuesEntity = true;
try {
configuration.addAnnotatedClass(Class.forName("com.blazebit.persistence.impl.function.entity.ValuesEntity"));
configuration.buildMappings();
valuesEntity = Class.forName("com.blazebit.persistence.impl.function.entity.ValuesEntity");
} catch (ClassNotFoundException e) {
throw new RuntimeException("Are you missing blaze-persistence-core-impl on the classpath?", e);
}
Expand All @@ -52,13 +53,22 @@ public void integrate(Configuration configuration, SessionFactoryImplementor ses
while (iter.hasNext()) {
PersistentClass clazz = iter.next();
Class<?> entityClass = clazz.getMappedClass();
if (valuesEntity.equals(entityClass)) {
registerValuesEntity = false;
}

if (entityClass.isAnnotationPresent(CTE.class)) {
clazz.getTable().setSubselect("select * from " + clazz.getJpaEntityName());
// TODO: check that no collections are mapped
}
}

if (registerValuesEntity) {
// Register values entity if wasn't found
configuration.addAnnotatedClass(valuesEntity);
configuration.buildMappings();
}

serviceRegistry.locateServiceBinding(PersisterClassResolver.class).setService(new CustomPersisterClassResolver());
serviceRegistry.locateServiceBinding(Database.class).setService(new SimpleDatabase(configuration.getTableMappings()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@ public Class getServiceInitiated() {

@Override
public void integrate(Configuration configuration, SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry) {
Class<?> valuesEntity;
boolean registerValuesEntity = true;
try {
configuration.addAnnotatedClass(Class.forName("com.blazebit.persistence.impl.function.entity.ValuesEntity"));
configuration.buildMappings();
valuesEntity = Class.forName("com.blazebit.persistence.impl.function.entity.ValuesEntity");
} catch (ClassNotFoundException e) {
throw new RuntimeException("Are you missing blaze-persistence-core-impl on the classpath?", e);
}
Expand All @@ -59,6 +60,12 @@ public void integrate(Configuration configuration, SessionFactoryImplementor ses
}
}

if (registerValuesEntity) {
// Register values entity if wasn't found
configuration.addAnnotatedClass(valuesEntity);
configuration.buildMappings();
}

serviceRegistry.locateServiceBinding(PersisterClassResolver.class).setService(new CustomPersisterClassResolver());
serviceRegistry.locateServiceBinding(Database.class).setService(new SimpleDatabase(configuration.getTableMappings()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ public class Hibernate52MetadataContributor implements MetadataContributor {

@Override
public void contribute(InFlightMetadataCollector metadataCollector, IndexView jandexIndex) {
// Skip if already registered
if (metadataCollector.getEntityBinding("com.blazebit.persistence.impl.function.entity.ValuesEntity") != null) {
return;
}

MetadataBuildingOptions options = metadataCollector.getMetadataBuildingOptions();
final ClassLoaderService classLoaderService = options.getServiceRegistry().getService( ClassLoaderService.class );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ public class Hibernate5MetadataContributor implements MetadataContributor {

@Override
public void contribute(InFlightMetadataCollector metadataCollector, IndexView jandexIndex) {
// Skip if already registered
if (metadataCollector.getEntityBinding("com.blazebit.persistence.impl.function.entity.ValuesEntity") != null) {
return;
}

MetadataBuildingOptions options = metadataCollector.getMetadataBuildingOptions();
final ClassLoaderService classLoaderService = options.getServiceRegistry().getService( ClassLoaderService.class );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ public class Hibernate60MetadataContributor implements MetadataContributor {

@Override
public void contribute(InFlightMetadataCollector metadataCollector, IndexView jandexIndex) {
// Skip if already registered
if (metadataCollector.getEntityBinding("com.blazebit.persistence.impl.function.entity.ValuesEntity") != null) {
return;
}

MetadataBuildingOptions options = metadataCollector.getMetadataBuildingOptions();
final ClassLoaderService classLoaderService = options.getServiceRegistry().getService( ClassLoaderService.class );

Expand Down

0 comments on commit e849496

Please sign in to comment.