Search in sources :

Example 71 with HibernateException

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);
    }
}
Also used : Transaction(javax.transaction.Transaction) SystemException(javax.transaction.SystemException) HibernateException(org.hibernate.HibernateException)

Example 72 with HibernateException

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);
    }
}
Also used : StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) MetadataBuilder(org.hibernate.boot.MetadataBuilder) HibernateException(org.hibernate.HibernateException) MetadataSources(org.hibernate.boot.MetadataSources) FileNotFoundException(java.io.FileNotFoundException) MetadataImplementor(org.hibernate.boot.spi.MetadataImplementor) BuildException(org.apache.tools.ant.BuildException) IOException(java.io.IOException) IOException(java.io.IOException) BuildException(org.apache.tools.ant.BuildException) FileNotFoundException(java.io.FileNotFoundException) HibernateException(org.hibernate.HibernateException) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry)

Example 73 with HibernateException

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);
    }
}
Also used : StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) MetadataBuilder(org.hibernate.boot.MetadataBuilder) HibernateException(org.hibernate.HibernateException) MetadataSources(org.hibernate.boot.MetadataSources) FileNotFoundException(java.io.FileNotFoundException) MetadataImplementor(org.hibernate.boot.spi.MetadataImplementor) BuildException(org.apache.tools.ant.BuildException) IOException(java.io.IOException) IOException(java.io.IOException) BuildException(org.apache.tools.ant.BuildException) FileNotFoundException(java.io.FileNotFoundException) HibernateException(org.hibernate.HibernateException) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry)

Example 74 with HibernateException

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();
}
Also used : HibernateException(org.hibernate.HibernateException) Iterator(java.util.Iterator)

Example 75 with HibernateException

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;
}
Also used : Subclass(org.hibernate.mapping.Subclass) ProxyFactory(org.hibernate.proxy.ProxyFactory) HibernateException(org.hibernate.HibernateException) Method(java.lang.reflect.Method) MappingException(org.hibernate.MappingException) Iterator(java.util.Iterator) PersistentClass(org.hibernate.mapping.PersistentClass) Property(org.hibernate.mapping.Property) CompositeType(org.hibernate.type.CompositeType)

Aggregations

HibernateException (org.hibernate.HibernateException)372 DAOException (org.jbei.ice.storage.DAOException)141 Session (org.hibernate.Session)72 Test (org.junit.Test)41 ArrayList (java.util.ArrayList)30 SQLException (java.sql.SQLException)27 IOException (java.io.IOException)15 TestForIssue (org.hibernate.testing.TestForIssue)15 Transaction (org.hibernate.Transaction)14 Group (org.jbei.ice.storage.model.Group)14 Type (org.hibernate.type.Type)12 PersistenceException (org.mifos.framework.exceptions.PersistenceException)12 Serializable (java.io.Serializable)11 EntityEntry (org.hibernate.engine.spi.EntityEntry)10 SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)10 HashMap (java.util.HashMap)9 Method (java.lang.reflect.Method)8 Dialect (org.hibernate.dialect.Dialect)8 CollectionPersister (org.hibernate.persister.collection.CollectionPersister)8 HibernateProxy (org.hibernate.proxy.HibernateProxy)8