use of org.hibernate.AnnotationException in project hibernate-orm by hibernate.
the class ColumnsBuilder method buildDefaultJoinColumnsForXToOne.
Ejb3JoinColumn[] buildDefaultJoinColumnsForXToOne(XProperty property, PropertyData inferredData) {
Ejb3JoinColumn[] joinColumns;
JoinTable joinTableAnn = propertyHolder.getJoinTable(property);
if (joinTableAnn != null) {
joinColumns = Ejb3JoinColumn.buildJoinColumns(joinTableAnn.inverseJoinColumns(), null, entityBinder.getSecondaryTables(), propertyHolder, inferredData.getPropertyName(), buildingContext);
if (StringHelper.isEmpty(joinTableAnn.name())) {
throw new AnnotationException("JoinTable.name() on a @ToOne association has to be explicit: " + BinderHelper.getPath(propertyHolder, inferredData));
}
} else {
OneToOne oneToOneAnn = property.getAnnotation(OneToOne.class);
String mappedBy = oneToOneAnn != null ? oneToOneAnn.mappedBy() : null;
joinColumns = Ejb3JoinColumn.buildJoinColumns(null, mappedBy, entityBinder.getSecondaryTables(), propertyHolder, inferredData.getPropertyName(), buildingContext);
}
return joinColumns;
}
use of org.hibernate.AnnotationException in project hibernate-orm by hibernate.
the class AnnotationBinder method bindTypeDef.
private static void bindTypeDef(TypeDef defAnn, MetadataBuildingContext context) {
Properties params = new Properties();
for (Parameter param : defAnn.parameters()) {
params.setProperty(param.name(), param.value());
}
if (BinderHelper.isEmptyAnnotationValue(defAnn.name()) && defAnn.defaultForType().equals(void.class)) {
throw new AnnotationException("Either name or defaultForType (or both) attribute should be set in TypeDef having typeClass " + defAnn.typeClass().getName());
}
final String typeBindMessageF = "Binding type definition: %s";
if (!BinderHelper.isEmptyAnnotationValue(defAnn.name())) {
if (LOG.isDebugEnabled()) {
LOG.debugf(typeBindMessageF, defAnn.name());
}
context.getMetadataCollector().addTypeDefinition(new TypeDefinition(defAnn.name(), defAnn.typeClass(), null, params));
}
if (!defAnn.defaultForType().equals(void.class)) {
if (LOG.isDebugEnabled()) {
LOG.debugf(typeBindMessageF, defAnn.defaultForType().getName());
}
context.getMetadataCollector().addTypeDefinition(new TypeDefinition(defAnn.defaultForType().getName(), defAnn.typeClass(), new String[] { defAnn.defaultForType().getName() }, params));
}
}
use of org.hibernate.AnnotationException in project hibernate-orm by hibernate.
the class AttributeConverterDescriptorImpl method create.
public static AttributeConverterDescriptor create(AttributeConverterDefinition definition, ClassmateContext classmateContext) {
final AttributeConverter converter = definition.getAttributeConverter();
final Class converterClass = converter.getClass();
final ResolvedType converterType = classmateContext.getTypeResolver().resolve(converterClass);
final List<ResolvedType> converterParamTypes = converterType.typeParametersFor(AttributeConverter.class);
if (converterParamTypes == null) {
throw new AnnotationException("Could not extract type parameter information from AttributeConverter implementation [" + converterClass.getName() + "]");
} else if (converterParamTypes.size() != 2) {
throw new AnnotationException("Unexpected type parameter information for AttributeConverter implementation [" + converterClass.getName() + "]; expected 2 parameter types, but found " + converterParamTypes.size());
}
return new AttributeConverterDescriptorImpl(converter, definition.isAutoApply(), converterParamTypes.get(0), converterParamTypes.get(1));
}
use of org.hibernate.AnnotationException in project hibernate-orm by hibernate.
the class JPAOverriddenAnnotationReader method getInheritance.
private Inheritance getInheritance(Element tree, XMLContext.Default defaults) {
Element element = tree != null ? tree.element("inheritance") : null;
if (element != null) {
AnnotationDescriptor ad = new AnnotationDescriptor(Inheritance.class);
Attribute attr = element.attribute("strategy");
InheritanceType strategy = InheritanceType.SINGLE_TABLE;
if (attr != null) {
String value = attr.getValue();
if ("SINGLE_TABLE".equals(value)) {
strategy = InheritanceType.SINGLE_TABLE;
} else if ("JOINED".equals(value)) {
strategy = InheritanceType.JOINED;
} else if ("TABLE_PER_CLASS".equals(value)) {
strategy = InheritanceType.TABLE_PER_CLASS;
} else {
throw new AnnotationException("Unknown InheritanceType in XML: " + value + " (" + SCHEMA_VALIDATION + ")");
}
}
ad.setValue("strategy", strategy);
return AnnotationFactory.create(ad);
} else if (defaults.canUseJavaAnnotations()) {
return getPhysicalAnnotation(Inheritance.class);
} else {
return null;
}
}
use of org.hibernate.AnnotationException in project hibernate-orm by hibernate.
the class QueryHintDefinition method getCacheMode.
public CacheMode getCacheMode(String query) {
String hitName = QueryHints.CACHE_MODE;
String value = (String) hintsMap.get(hitName);
if (value == null) {
return null;
}
try {
return CacheMode.interpretExternalSetting(value);
} catch (MappingException e) {
throw new AnnotationException("Unknown CacheMode in hint: " + query + ":" + hitName, e);
}
}
Aggregations