use of org.hibernate.AnnotationException in project hibernate-orm by hibernate.
the class JpaXsdVersionsTest method testInvalidOrm1.
@Test
public void testInvalidOrm1() {
PersistenceUnitInfoImpl pui = new PersistenceUnitInfoImpl("invalid-orm1-test", "1.0").addMappingFileName("org/hibernate/test/jpa/xml/versions/invalid-orm-1_0.xml");
HibernatePersistenceProvider hp = new HibernatePersistenceProvider();
EntityManagerFactory emf = null;
try {
emf = hp.createContainerEntityManagerFactory(pui, Collections.EMPTY_MAP);
Assert.fail("expecting 'invalid content' error");
} catch (InvalidMappingException | AnnotationException expected) {
// expected condition
} catch (PersistenceException expected) {
// expected condition
} finally {
if (emf != null) {
emf.close();
}
}
}
use of org.hibernate.AnnotationException in project hibernate-orm by hibernate.
the class JPAOverriddenAnnotationReader method getDiscriminatorColumn.
private DiscriminatorColumn getDiscriminatorColumn(Element tree, XMLContext.Default defaults) {
Element element = tree != null ? tree.element("discriminator-column") : null;
if (element != null) {
AnnotationDescriptor ad = new AnnotationDescriptor(DiscriminatorColumn.class);
copyStringAttribute(ad, element, "name", false);
copyStringAttribute(ad, element, "column-definition", false);
String value = element.attributeValue("discriminator-type");
DiscriminatorType type = DiscriminatorType.STRING;
if (value != null) {
if ("STRING".equals(value)) {
type = DiscriminatorType.STRING;
} else if ("CHAR".equals(value)) {
type = DiscriminatorType.CHAR;
} else if ("INTEGER".equals(value)) {
type = DiscriminatorType.INTEGER;
} else {
throw new AnnotationException("Unknown DiscrimiatorType in XML: " + value + " (" + SCHEMA_VALIDATION + ")");
}
}
ad.setValue("discriminatorType", type);
copyIntegerAttribute(ad, element, "length");
return AnnotationFactory.create(ad);
} else if (defaults.canUseJavaAnnotations()) {
return getPhysicalAnnotation(DiscriminatorColumn.class);
} else {
return null;
}
}
use of org.hibernate.AnnotationException in project hibernate-orm by hibernate.
the class InheritanceState method getElementsToProcess.
/*
* Get the annotated elements and determine access type from hierarchy, guessing from @Id or @EmbeddedId presence if not
* specified.
* Change EntityBinder by side effect
*/
public ElementsToProcess getElementsToProcess() {
if (elementsToProcess == null) {
InheritanceState inheritanceState = inheritanceStatePerClass.get(clazz);
assert !inheritanceState.isEmbeddableSuperclass();
getMappedSuperclassesTillNextEntityOrdered();
accessType = determineDefaultAccessType();
ArrayList<PropertyData> elements = new ArrayList<PropertyData>();
int idPropertyCount = 0;
for (XClass classToProcessForMappedSuperclass : classesToProcessForMappedSuperclass) {
PropertyContainer propertyContainer = new PropertyContainer(classToProcessForMappedSuperclass, clazz, accessType);
int currentIdPropertyCount = AnnotationBinder.addElementsOfClass(elements, propertyContainer, buildingContext);
idPropertyCount += currentIdPropertyCount;
}
if (idPropertyCount == 0 && !inheritanceState.hasParents()) {
throw new AnnotationException("No identifier specified for entity: " + clazz.getName());
}
elements.trimToSize();
elementsToProcess = new ElementsToProcess(elements, idPropertyCount);
}
return elementsToProcess;
}
use of org.hibernate.AnnotationException in project hibernate-orm by hibernate.
the class JPAOverriddenAnnotationReader method getEnumerated.
private void getEnumerated(List<Annotation> annotationList, Element element) {
Element subElement = element != null ? element.element("enumerated") : null;
if (subElement != null) {
AnnotationDescriptor ad = new AnnotationDescriptor(Enumerated.class);
String enumerated = subElement.getTextTrim();
if ("ORDINAL".equalsIgnoreCase(enumerated)) {
ad.setValue("value", EnumType.ORDINAL);
} else if ("STRING".equalsIgnoreCase(enumerated)) {
ad.setValue("value", EnumType.STRING);
} else if (StringHelper.isNotEmpty(enumerated)) {
throw new AnnotationException("Unknown EnumType: " + enumerated + ". " + SCHEMA_VALIDATION);
}
annotationList.add(AnnotationFactory.create(ad));
}
}
use of org.hibernate.AnnotationException in project hibernate-orm by hibernate.
the class JPAOverriddenAnnotationReader method getAccessType.
private void getAccessType(List<Annotation> annotationList, Element element) {
if (element == null) {
return;
}
String access = element.attributeValue("access");
if (access != null) {
AnnotationDescriptor ad = new AnnotationDescriptor(Access.class);
AccessType type;
try {
type = AccessType.valueOf(access);
} catch (IllegalArgumentException e) {
throw new AnnotationException(access + " is not a valid access type. Check you xml confguration.");
}
if ((AccessType.PROPERTY.equals(type) && this.element instanceof Method) || (AccessType.FIELD.equals(type) && this.element instanceof Field)) {
return;
}
ad.setValue("value", type);
annotationList.add(AnnotationFactory.create(ad));
}
}
Aggregations