use of org.hibernate.HibernateException in project hibernate-orm by hibernate.
the class JtaIsolationDelegate method doInSuspendedTransaction.
private <T> T doInSuspendedTransaction(HibernateCallable<T> callable) {
try {
// First we suspend any current JTA transaction
Transaction surroundingTransaction = transactionManager.suspend();
LOG.debugf("Surrounding JTA transaction suspended [%s]", surroundingTransaction);
boolean hadProblems = false;
try {
return callable.call();
} catch (HibernateException e) {
hadProblems = true;
throw e;
} finally {
try {
transactionManager.resume(surroundingTransaction);
LOG.debugf("Surrounding JTA transaction resumed [%s]", surroundingTransaction);
} catch (Throwable t) {
// if the actually work had an error use that, otherwise error based on t
if (!hadProblems) {
//noinspection ThrowFromFinallyBlock
throw new HibernateException("Unable to resume previously suspended transaction", t);
}
}
}
} catch (SystemException e) {
throw new HibernateException("Unable to suspend current JTA transaction", e);
}
}
use of org.hibernate.HibernateException in project hibernate-orm by hibernate.
the class SchemaUpdateTask method execute.
/**
* Execute the task
*/
@Override
public void execute() throws BuildException {
log("Running Hibernate Core SchemaUpdate.");
log("This is an Ant task supporting only mapping files, if you want to use annotations see http://tools.hibernate.org.");
try {
final StandardServiceRegistryBuilder ssrBuilder = new StandardServiceRegistryBuilder();
configure(ssrBuilder);
final StandardServiceRegistry ssr = ssrBuilder.build();
final MetadataSources metadataSources = new MetadataSources(ssr);
configure(metadataSources);
final MetadataBuilder metadataBuilder = metadataSources.getMetadataBuilder();
configure(metadataBuilder, ssr);
final MetadataImplementor metadata = (MetadataImplementor) metadataBuilder.build();
new SchemaUpdate().setOutputFile(outputFile.getPath()).setDelimiter(delimiter).setHaltOnError(haltOnError).execute(TargetTypeHelper.parseLegacyCommandLineOptions(!quiet, !text, outputFile.getPath()), metadata);
} catch (HibernateException e) {
throw new BuildException("Schema text failed: " + e.getMessage(), e);
} catch (FileNotFoundException e) {
throw new BuildException("File not found: " + e.getMessage(), e);
} catch (IOException e) {
throw new BuildException("IOException : " + e.getMessage(), e);
} catch (BuildException e) {
throw e;
} catch (Exception e) {
throw new BuildException(e);
}
}
use of org.hibernate.HibernateException in project hibernate-orm by hibernate.
the class SchemaValidatorTask method execute.
/**
* Execute the task
*/
@Override
public void execute() throws BuildException {
try {
final StandardServiceRegistryBuilder ssrBuilder = new StandardServiceRegistryBuilder();
configure(ssrBuilder);
final StandardServiceRegistry ssr = ssrBuilder.build();
try {
final MetadataSources metadataSources = new MetadataSources(ssrBuilder.build());
configure(metadataSources);
final MetadataBuilder metadataBuilder = metadataSources.getMetadataBuilder();
configure(metadataBuilder, ssr);
final MetadataImplementor metadata = (MetadataImplementor) metadataBuilder.build();
new SchemaValidator().validate(metadata, ssr);
} finally {
StandardServiceRegistryBuilder.destroy(ssr);
}
} catch (HibernateException e) {
throw new BuildException("Schema text failed: " + e.getMessage(), e);
} catch (FileNotFoundException e) {
throw new BuildException("File not found: " + e.getMessage(), e);
} catch (IOException e) {
throw new BuildException("IOException : " + e.getMessage(), e);
} catch (BuildException e) {
throw e;
} catch (Exception e) {
throw new BuildException(e);
}
}
use of org.hibernate.HibernateException in project hibernate-orm by hibernate.
the class InsertSelect method toStatementString.
public String toStatementString() {
if (tableName == null) {
throw new HibernateException("no table name defined for insert-select");
}
if (select == null) {
throw new HibernateException("no select defined for insert-select");
}
StringBuilder buf = new StringBuilder((columnNames.size() * 15) + tableName.length() + 10);
if (comment != null) {
buf.append("/* ").append(comment).append(" */ ");
}
buf.append("insert into ").append(tableName);
if (!columnNames.isEmpty()) {
buf.append(" (");
Iterator itr = columnNames.iterator();
while (itr.hasNext()) {
buf.append(itr.next());
if (itr.hasNext()) {
buf.append(", ");
}
}
buf.append(")");
}
buf.append(' ').append(select.toStatementString());
return buf.toString();
}
use of org.hibernate.HibernateException 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;
}
Aggregations