use of org.hibernate.MappingException in project hibernate-orm by hibernate.
the class PojoEntityTuplizer method buildProxyFactory.
@Override
protected ProxyFactory buildProxyFactory(PersistentClass persistentClass, Getter idGetter, Setter idSetter) {
// determine the id getter and setter methods from the proxy interface (if any)
// determine all interfaces needed by the resulting proxy
/*
* We need to preserve the order of the interfaces they were put into the set, since javassist will choose the
* first one's class-loader to construct the proxy class with. This is also the reason why HibernateProxy.class
* should be the last one in the order (on JBossAS7 its class-loader will be org.hibernate module's class-
* loader, which will not see the classes inside deployed apps. See HHH-3078
*/
Set<Class> proxyInterfaces = new java.util.LinkedHashSet<Class>();
Class mappedClass = persistentClass.getMappedClass();
Class proxyInterface = persistentClass.getProxyInterface();
if (proxyInterface != null && !mappedClass.equals(proxyInterface)) {
if (!proxyInterface.isInterface()) {
throw new MappingException("proxy must be either an interface, or the class itself: " + getEntityName());
}
proxyInterfaces.add(proxyInterface);
}
if (mappedClass.isInterface()) {
proxyInterfaces.add(mappedClass);
}
Iterator<Subclass> subclasses = persistentClass.getSubclassIterator();
while (subclasses.hasNext()) {
final Subclass subclass = subclasses.next();
final Class subclassProxy = subclass.getProxyInterface();
final Class subclassClass = subclass.getMappedClass();
if (subclassProxy != null && !subclassClass.equals(subclassProxy)) {
if (!subclassProxy.isInterface()) {
throw new MappingException("proxy must be either an interface, or the class itself: " + subclass.getEntityName());
}
proxyInterfaces.add(subclassProxy);
}
}
proxyInterfaces.add(HibernateProxy.class);
Iterator properties = persistentClass.getPropertyIterator();
Class clazz = persistentClass.getMappedClass();
while (properties.hasNext()) {
Property property = (Property) properties.next();
Method method = property.getGetter(clazz).getMethod();
if (method != null && Modifier.isFinal(method.getModifiers())) {
LOG.gettersOfLazyClassesCannotBeFinal(persistentClass.getEntityName(), property.getName());
}
method = property.getSetter(clazz).getMethod();
if (method != null && Modifier.isFinal(method.getModifiers())) {
LOG.settersOfLazyClassesCannotBeFinal(persistentClass.getEntityName(), property.getName());
}
}
Method idGetterMethod = idGetter == null ? null : idGetter.getMethod();
Method idSetterMethod = idSetter == null ? null : idSetter.getMethod();
Method proxyGetIdentifierMethod = idGetterMethod == null || proxyInterface == null ? null : ReflectHelper.getMethod(proxyInterface, idGetterMethod);
Method proxySetIdentifierMethod = idSetterMethod == null || proxyInterface == null ? null : ReflectHelper.getMethod(proxyInterface, idSetterMethod);
ProxyFactory pf = buildProxyFactoryInternal(persistentClass, idGetter, idSetter);
try {
pf.postInstantiate(getEntityName(), mappedClass, proxyInterfaces, proxyGetIdentifierMethod, proxySetIdentifierMethod, persistentClass.hasEmbeddedIdentifier() ? (CompositeType) persistentClass.getIdentifier().getType() : null);
} catch (HibernateException he) {
LOG.unableToCreateProxyFactory(getEntityName(), he);
pf = null;
}
return pf;
}
use of org.hibernate.MappingException in project hibernate-orm by hibernate.
the class TypeFactory method type.
public Type type(Class<Type> typeClass, Properties parameters) {
try {
Type type = typeClass.newInstance();
injectParameters(type, parameters);
return type;
} catch (Exception e) {
throw new MappingException("Could not instantiate Type: " + typeClass.getName(), e);
}
}
use of org.hibernate.MappingException in project hibernate-orm by hibernate.
the class TypeFactory method customCollection.
public CollectionType customCollection(String typeName, Properties typeParameters, String role, String propertyRef) {
Class typeClass;
try {
typeClass = ReflectHelper.classForName(typeName);
} catch (ClassNotFoundException cnfe) {
throw new MappingException("user collection type class not found: " + typeName, cnfe);
}
CustomCollectionType result = new CustomCollectionType(typeScope, typeClass, role, propertyRef);
if (typeParameters != null) {
injectParameters(result.getUserType(), typeParameters);
}
return result;
}
use of org.hibernate.MappingException in project querydsl by querydsl.
the class JPADomainExporter method handleProperty.
private void handleProperty(EntityType entityType, Class<?> cl, Attribute<?, ?> p) throws NoSuchMethodException, ClassNotFoundException {
Class<?> clazz = Object.class;
try {
clazz = p.getJavaType();
} catch (MappingException e) {
// ignore
}
Type propertyType = getType(cl, clazz, p.getName());
AnnotatedElement annotated = getAnnotatedElement(cl, p.getName());
propertyType = getTypeOverride(propertyType, annotated);
if (propertyType == null) {
return;
}
if (p.isCollection()) {
if (p instanceof MapAttribute) {
MapAttribute<?, ?, ?> map = (MapAttribute<?, ?, ?>) p;
Type keyType = typeFactory.get(map.getKeyJavaType());
Type valueType = typeFactory.get(map.getElementType().getJavaType());
valueType = getPropertyType(p, valueType);
propertyType = new SimpleType(propertyType, normalize(propertyType.getParameters().get(0), keyType), normalize(propertyType.getParameters().get(1), valueType));
} else {
Type valueType = typeFactory.get(((PluralAttribute<?, ?, ?>) p).getElementType().getJavaType());
valueType = getPropertyType(p, valueType);
propertyType = new SimpleType(propertyType, normalize(propertyType.getParameters().get(0), valueType));
}
} else {
propertyType = getPropertyType(p, propertyType);
}
Property property = createProperty(entityType, p.getName(), propertyType, annotated);
entityType.addProperty(property);
}
use of org.hibernate.MappingException in project hibernate-orm by hibernate.
the class AuditedDynamicComponentTest method testAuditedDynamicComponentFailure.
//@Test
public void testAuditedDynamicComponentFailure() throws URISyntaxException {
final Configuration config = new Configuration();
final URL hbm = Thread.currentThread().getContextClassLoader().getResource("mappings/dynamicComponents/mapAudited.hbm.xml");
config.addFile(new File(hbm.toURI()));
final String auditStrategy = getAuditStrategy();
if (!StringTools.isEmpty(auditStrategy)) {
config.setProperty(EnversSettings.AUDIT_STRATEGY, auditStrategy);
}
final ServiceRegistry serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry(config.getProperties());
try {
config.buildSessionFactory(serviceRegistry);
Assert.fail("MappingException expected");
} catch (MappingException e) {
Assert.assertEquals("Audited dynamic-component properties are not supported. Consider applying @NotAudited annotation to " + AuditedDynamicComponentEntity.class.getName() + "#customFields.", e.getMessage());
} finally {
ServiceRegistryBuilder.destroy(serviceRegistry);
}
}
Aggregations