Skip to content

Commit

Permalink
Added a warning log message for entity classes without single id attr…
Browse files Browse the repository at this point in the history
…ibute.
  • Loading branch information
vjlamp committed Oct 16, 2024
1 parent 0cf1402 commit 920745a
Showing 1 changed file with 22 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import org.apache.tapestry5.services.dashboard.DashboardTab;
import org.apache.tapestry5.services.transform.ComponentClassTransformWorker2;
import org.hibernate.Session;
import org.slf4j.Logger;

/**
* Supplements the services defined by {@link org.apache.tapestry5.hibernate.modules.HibernateCoreModule} with additional
Expand Down Expand Up @@ -93,7 +94,7 @@ public static void contributeValueEncoderSource(
@Symbol(HibernateSymbols.PROVIDE_ENTITY_VALUE_ENCODERS) boolean provideEncoders,
final HibernateSessionSource sessionSource, final Session session,
final TypeCoercer typeCoercer, final PropertyAccess propertyAccess,
final LoggerSource loggerSource)
final LoggerSource loggerSource, final Logger logger)
{
if (!provideEncoders)
return;
Expand All @@ -102,23 +103,27 @@ public static void contributeValueEncoderSource(
for (EntityType<?> entityType : entities)
{
Class<?> entityClass = entityType.getJavaType();
if (entityClass != null && entityType.hasSingleIdAttribute())
{
SingularAttribute<?, ?> id = entityType.getId(entityType.getIdType().getJavaType());
final String idenfierPropertyName = id.getName();
ValueEncoderFactory factory = new ValueEncoderFactory()
if (entityClass != null)
{
if (entityType.hasSingleIdAttribute())
{
@Override
public ValueEncoder create(Class type)
{
return new HibernateEntityValueEncoder(entityClass, idenfierPropertyName,
session, propertyAccess, typeCoercer,
loggerSource.getLogger(entityClass));
}
};

configuration.add(entityClass, factory);

SingularAttribute<?, ?> id = entityType.getId(entityType.getIdType().getJavaType());
final String idenfierPropertyName = id.getName();
ValueEncoderFactory factory = new ValueEncoderFactory()
{
@Override
public ValueEncoder create(Class type)
{
return new HibernateEntityValueEncoder(entityClass, idenfierPropertyName,
session, propertyAccess, typeCoercer,
loggerSource.getLogger(entityClass));
}
};

configuration.add(entityClass, factory);
} else {
logger.warn("Not creating a value encoder for {} as it does not have a single id attribute.", entityClass);
}
}
}
}
Expand Down

0 comments on commit 920745a

Please sign in to comment.