use of org.hibernate.MappingException in project hibernate-orm by hibernate.
the class FromElementType method getPropertyType.
/**
* Returns the type of a property, given it's name (the last part) and the full path.
*
* @param propertyName The last part of the full path to the property.
*
* @return The type.
*
* @0param getPropertyPath The full property path.
*/
public Type getPropertyType(String propertyName, String propertyPath) {
checkInitialized();
Type type = null;
// we'd need to "fall through" to using the property mapping.
if (persister != null && propertyName.equals(propertyPath) && propertyName.equals(persister.getIdentifierPropertyName())) {
type = persister.getIdentifierType();
} else {
// Otherwise, use the property mapping.
PropertyMapping mapping = getPropertyMapping(propertyName);
type = mapping.toType(propertyPath);
}
if (type == null) {
throw new MappingException("Property " + propertyName + " does not exist in " + ((queryableCollection == null) ? "class" : "collection") + " " + ((queryableCollection == null) ? fromElement.getClassName() : queryableCollection.getRole()));
}
return type;
}
use of org.hibernate.MappingException in project hibernate-orm by hibernate.
the class TypeFactory method custom.
/**
* @deprecated Only for use temporary use by {@link org.hibernate.Hibernate}
*/
@Deprecated
public static CustomType custom(Class<UserType> typeClass, Properties parameters, TypeScope scope) {
try {
UserType userType = typeClass.newInstance();
injectParameters(userType, parameters);
return new CustomType(userType);
} catch (Exception e) {
throw new MappingException("Unable to instantiate custom type: " + typeClass.getName(), e);
}
}
use of org.hibernate.MappingException in project hibernate-orm by hibernate.
the class TypeFactory method customComponent.
/**
* @deprecated Only for use temporary use by {@link org.hibernate.Hibernate}
*/
@Deprecated
@SuppressWarnings({ "JavaDoc" })
public static CompositeCustomType customComponent(Class<CompositeUserType> typeClass, Properties parameters, TypeScope scope) {
try {
CompositeUserType userType = typeClass.newInstance();
injectParameters(userType, parameters);
return new CompositeCustomType(userType);
} catch (Exception e) {
throw new MappingException("Unable to instantiate custom type: " + typeClass.getName(), e);
}
}
use of org.hibernate.MappingException in project hibernate-orm by hibernate.
the class FetchProfileTest method testXmlOverride.
@Test
public void testXmlOverride() {
Configuration config = new Configuration();
config.addAnnotatedClass(Customer5.class);
config.addAnnotatedClass(Order.class);
config.addAnnotatedClass(Country.class);
InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("org/hibernate/test/annotations/fetchprofile/mappings.hbm.xml");
config.addInputStream(is);
SessionFactoryImplementor sessionImpl = (SessionFactoryImplementor) config.buildSessionFactory(serviceRegistry);
assertTrue("fetch profile not parsed properly", sessionImpl.containsFetchProfileDefinition("orders-profile"));
sessionImpl.close();
// now the same with no xml
final MetadataSources metadataSources = new MetadataSources().addAnnotatedClass(Customer5.class).addAnnotatedClass(Order.class).addAnnotatedClass(Country.class);
try {
metadataSources.buildMetadata();
fail();
} catch (MappingException e) {
log.trace("success");
} finally {
ServiceRegistry metaServiceRegistry = metadataSources.getServiceRegistry();
if (metaServiceRegistry instanceof BootstrapServiceRegistry) {
BootstrapServiceRegistryBuilder.destroy(metaServiceRegistry);
}
}
}
use of org.hibernate.MappingException in project hibernate-orm by hibernate.
the class FetchProfileTest method testWrongAssociationName.
@Test
public void testWrongAssociationName() {
final MetadataSources metadataSources = new MetadataSources().addAnnotatedClass(Customer2.class).addAnnotatedClass(Order.class).addAnnotatedClass(Country.class);
try {
metadataSources.buildMetadata();
fail();
} catch (MappingException e) {
log.trace("success");
} finally {
ServiceRegistry metaServiceRegistry = metadataSources.getServiceRegistry();
if (metaServiceRegistry instanceof BootstrapServiceRegistry) {
BootstrapServiceRegistryBuilder.destroy(metaServiceRegistry);
}
}
}
Aggregations