mapKeyClass = mapKeyClassAnn.value();
}
if (mapKeyClass == null)
{
throw new InvalidEntityDefinitionException(
"For a Map relationship field,"
+ " it is mandatory to specify Map key class either using @MapKeyClass annotation or through generics");
}
}
// Check for target class specified at annotation
if (targetEntity == null && null != m2mAnnotation.targetEntity()
&& !m2mAnnotation.targetEntity().getSimpleName().equals("void"))
{
targetEntity = m2mAnnotation.targetEntity();
}
//check if target entity is null
if (targetEntity == null)
{
throw new InvalidEntityDefinitionException("Could not determine target entity class for relationship."
+ " It should either be specified using targetEntity attribute of @ManyToMany or through generics");
}
//check if joined by foreign key
if (isJoinedByFK)
{
throw new InvalidEntityDefinitionException(
"@JoinColumn not allowed for ManyToMany relationship. Use @JoinTable instead");
}
//check if joined by foreign key and join column name is set
if (isJoinedByMap)
{
MapKeyJoinColumn mapKeyJoinColumnAnn = relationField.getAnnotation(MapKeyJoinColumn.class);
if (mapKeyJoinColumnAnn != null)
{
String mapKeyJoinColumnName = mapKeyJoinColumnAnn.name();
if (StringUtils.isEmpty(mapKeyJoinColumnName))
{
throw new InvalidEntityDefinitionException(
"It's mandatory to specify name attribute with @MapKeyJoinColumn annotation");
}
}
}
//check if not joined by table in many to many
if (!isJoinedByTable && !isJoinedByMap
&& (m2mAnnotation.mappedBy() == null || m2mAnnotation.mappedBy().isEmpty()))
{
throw new InvalidEntityDefinitionException(
"It's manadatory to use @JoinTable with parent side of ManyToMany relationship.");
}
return true;
}