use of org.hibernate.MappingException in project hibernate-orm by hibernate.
the class SimpleValue method getType.
public Type getType() throws MappingException {
if (type != null) {
return type;
}
if (typeName == null) {
throw new MappingException("No type name");
}
if (typeParameters != null && Boolean.valueOf(typeParameters.getProperty(DynamicParameterizedType.IS_DYNAMIC)) && typeParameters.get(DynamicParameterizedType.PARAMETER_TYPE) == null) {
createParameterImpl();
}
Type result = metadata.getTypeResolver().heuristicType(typeName, typeParameters);
// instead of BinaryType (HHH-10413)
if (isVersion && BinaryType.class.isInstance(result)) {
log.debug("version is BinaryType; changing to RowVersionType");
result = RowVersionType.INSTANCE;
}
if (result == null) {
String msg = "Could not determine type for: " + typeName;
if (table != null) {
msg += ", at table: " + table.getName();
}
if (columns != null && columns.size() > 0) {
msg += ", for columns: " + columns;
}
throw new MappingException(msg);
}
return result;
}
use of org.hibernate.MappingException in project hibernate-orm by hibernate.
the class AbstractEntityPersister method getNaturalIdentifierSnapshot.
public Object[] getNaturalIdentifierSnapshot(Serializable id, SharedSessionContractImplementor session) throws HibernateException {
if (!hasNaturalIdentifier()) {
throw new MappingException("persistent class did not define a natural-id : " + MessageHelper.infoString(this));
}
if (LOG.isTraceEnabled()) {
LOG.tracev("Getting current natural-id snapshot state for: {0}", MessageHelper.infoString(this, id, getFactory()));
}
int[] naturalIdPropertyIndexes = getNaturalIdentifierProperties();
int naturalIdPropertyCount = naturalIdPropertyIndexes.length;
boolean[] naturalIdMarkers = new boolean[getPropertySpan()];
Type[] extractionTypes = new Type[naturalIdPropertyCount];
for (int i = 0; i < naturalIdPropertyCount; i++) {
extractionTypes[i] = getPropertyTypes()[naturalIdPropertyIndexes[i]];
naturalIdMarkers[naturalIdPropertyIndexes[i]] = true;
}
///////////////////////////////////////////////////////////////////////
// TODO : look at perhaps caching this...
Select select = new Select(getFactory().getDialect());
if (getFactory().getSessionFactoryOptions().isCommentsEnabled()) {
select.setComment("get current natural-id state " + getEntityName());
}
select.setSelectClause(concretePropertySelectFragmentSansLeadingComma(getRootAlias(), naturalIdMarkers));
select.setFromClause(fromTableFragment(getRootAlias()) + fromJoinFragment(getRootAlias(), true, false));
String[] aliasedIdColumns = StringHelper.qualify(getRootAlias(), getIdentifierColumnNames());
String whereClause = new StringBuilder().append(StringHelper.join("=? and ", aliasedIdColumns)).append("=?").append(whereJoinFragment(getRootAlias(), true, false)).toString();
String sql = select.setOuterJoins("", "").setWhereClause(whereClause).toStatementString();
///////////////////////////////////////////////////////////////////////
Object[] snapshot = new Object[naturalIdPropertyCount];
try {
PreparedStatement ps = session.getJdbcCoordinator().getStatementPreparer().prepareStatement(sql);
try {
getIdentifierType().nullSafeSet(ps, id, 1, session);
ResultSet rs = session.getJdbcCoordinator().getResultSetReturn().extract(ps);
try {
//if there is no resulting row, return null
if (!rs.next()) {
return null;
}
final EntityKey key = session.generateEntityKey(id, this);
Object owner = session.getPersistenceContext().getEntity(key);
for (int i = 0; i < naturalIdPropertyCount; i++) {
snapshot[i] = extractionTypes[i].hydrate(rs, getPropertyAliases("", naturalIdPropertyIndexes[i]), session, null);
if (extractionTypes[i].isEntityType()) {
snapshot[i] = extractionTypes[i].resolve(snapshot[i], session, owner);
}
}
return snapshot;
} finally {
session.getJdbcCoordinator().getResourceRegistry().release(rs, ps);
}
} finally {
session.getJdbcCoordinator().getResourceRegistry().release(ps);
session.getJdbcCoordinator().afterStatementExecution();
}
} catch (SQLException e) {
throw getFactory().getSQLExceptionHelper().convert(e, "could not retrieve snapshot: " + MessageHelper.infoString(this, id, getFactory()), sql);
}
}
use of org.hibernate.MappingException in project hibernate-orm by hibernate.
the class PersistentClass method validate.
public void validate(Mapping mapping) throws MappingException {
Iterator iter = getPropertyIterator();
while (iter.hasNext()) {
Property prop = (Property) iter.next();
if (!prop.isValid(mapping)) {
throw new MappingException("property mapping has wrong number of columns: " + StringHelper.qualify(getEntityName(), prop.getName()) + " type: " + prop.getType().getName());
}
}
checkPropertyDuplication();
checkColumnDuplication();
}
use of org.hibernate.MappingException in project hibernate-orm by hibernate.
the class PersistentClass method checkPropertyDuplication.
private void checkPropertyDuplication() throws MappingException {
HashSet<String> names = new HashSet<String>();
Iterator iter = getPropertyIterator();
while (iter.hasNext()) {
Property prop = (Property) iter.next();
if (!names.add(prop.getName())) {
throw new MappingException("Duplicate property mapping of " + prop.getName() + " found in " + getEntityName());
}
}
}
use of org.hibernate.MappingException 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