Search in sources :

Example 21 with HibernateException

use of org.hibernate.HibernateException in project spring-framework by spring-projects.

the class OpenSessionInterceptor method openSession.

/**
	 * Open a Session for the SessionFactory that this interceptor uses.
	 * <p>The default implementation delegates to the {@link SessionFactory#openSession}
	 * method and sets the {@link Session}'s flush mode to "MANUAL".
	 * @return the Session to use
	 * @throws DataAccessResourceFailureException if the Session could not be created
	 * @see FlushMode#MANUAL
	 */
@SuppressWarnings("deprecation")
protected Session openSession() throws DataAccessResourceFailureException {
    try {
        Session session = getSessionFactory().openSession();
        session.setFlushMode(FlushMode.MANUAL);
        return session;
    } catch (HibernateException ex) {
        throw new DataAccessResourceFailureException("Could not open Hibernate Session", ex);
    }
}
Also used : HibernateException(org.hibernate.HibernateException) DataAccessResourceFailureException(org.springframework.dao.DataAccessResourceFailureException) Session(org.hibernate.Session)

Example 22 with HibernateException

use of org.hibernate.HibernateException in project hibernate-orm by hibernate.

the class AttributeConverterDescriptorImpl method shouldAutoApplyToCollectionElement.

@Override
public boolean shouldAutoApplyToCollectionElement(XProperty xProperty, MetadataBuildingContext context) {
    if (!autoApply) {
        return false;
    }
    final ResolvedMember collectionMember = resolveMember(xProperty, context);
    final ResolvedType elementType;
    if (Map.class.isAssignableFrom(collectionMember.getType().getErasedType())) {
        elementType = collectionMember.getType().typeParametersFor(Map.class).get(1);
    } else if (Collection.class.isAssignableFrom(collectionMember.getType().getErasedType())) {
        elementType = collectionMember.getType().typeParametersFor(Collection.class).get(0);
    } else {
        throw new HibernateException("Attribute was neither a Collection nor a Map : " + collectionMember.getType().getErasedType());
    }
    return typesMatch(domainType, elementType);
}
Also used : ResolvedMember(com.fasterxml.classmate.members.ResolvedMember) HibernateException(org.hibernate.HibernateException) Collection(java.util.Collection) ResolvedType(com.fasterxml.classmate.ResolvedType)

Example 23 with HibernateException

use of org.hibernate.HibernateException in project hibernate-orm by hibernate.

the class AttributeConverterDescriptorImpl method shouldAutoApplyToMapKey.

@Override
public boolean shouldAutoApplyToMapKey(XProperty xProperty, MetadataBuildingContext context) {
    if (!autoApply) {
        return false;
    }
    final ResolvedMember collectionMember = resolveMember(xProperty, context);
    final ResolvedType keyType;
    if (Map.class.isAssignableFrom(collectionMember.getType().getErasedType())) {
        keyType = collectionMember.getType().typeParametersFor(Map.class).get(0);
    } else {
        throw new HibernateException("Attribute was not a Map : " + collectionMember.getType().getErasedType());
    }
    return typesMatch(domainType, keyType);
}
Also used : ResolvedMember(com.fasterxml.classmate.members.ResolvedMember) HibernateException(org.hibernate.HibernateException) ResolvedType(com.fasterxml.classmate.ResolvedType)

Example 24 with HibernateException

use of org.hibernate.HibernateException in project hibernate-orm by hibernate.

the class AttributeConverterDescriptorImpl method resolveMember.

private ResolvedMember resolveMember(XProperty xProperty, MetadataBuildingContext buildingContext) {
    final ClassmateContext classmateContext = buildingContext.getMetadataCollector().getClassmateContext();
    final ReflectionManager reflectionManager = buildingContext.getBuildingOptions().getReflectionManager();
    final ResolvedType declaringClassType = classmateContext.getTypeResolver().resolve(reflectionManager.toClass(xProperty.getDeclaringClass()));
    final ResolvedTypeWithMembers declaringClassWithMembers = classmateContext.getMemberResolver().resolve(declaringClassType, null, null);
    final Member member = toMember(xProperty);
    if (member instanceof Method) {
        for (ResolvedMethod resolvedMember : declaringClassWithMembers.getMemberMethods()) {
            if (resolvedMember.getName().equals(member.getName())) {
                return resolvedMember;
            }
        }
    } else if (member instanceof Field) {
        for (ResolvedField resolvedMember : declaringClassWithMembers.getMemberFields()) {
            if (resolvedMember.getName().equals(member.getName())) {
                return resolvedMember;
            }
        }
    } else {
        throw new HibernateException("Unexpected java.lang.reflect.Member type from org.hibernate.annotations.common.reflection.java.JavaXMember : " + member);
    }
    throw new HibernateException("Could not locate resolved type information for attribute [" + member.getName() + "] from Classmate");
}
Also used : Field(java.lang.reflect.Field) ResolvedField(com.fasterxml.classmate.members.ResolvedField) ResolvedMethod(com.fasterxml.classmate.members.ResolvedMethod) ResolvedField(com.fasterxml.classmate.members.ResolvedField) ReflectionManager(org.hibernate.annotations.common.reflection.ReflectionManager) HibernateException(org.hibernate.HibernateException) ResolvedMethod(com.fasterxml.classmate.members.ResolvedMethod) Method(java.lang.reflect.Method) Member(java.lang.reflect.Member) ResolvedMember(com.fasterxml.classmate.members.ResolvedMember) ResolvedType(com.fasterxml.classmate.ResolvedType) ResolvedTypeWithMembers(com.fasterxml.classmate.ResolvedTypeWithMembers)

Example 25 with HibernateException

use of org.hibernate.HibernateException in project hibernate-orm by hibernate.

the class EnhancerImpl method getByteCode.

private byte[] getByteCode(CtClass managedCtClass) {
    ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
    DataOutputStream out = new DataOutputStream(byteStream);
    try {
        managedCtClass.toBytecode(out);
        return byteStream.toByteArray();
    } catch (Exception e) {
        log.unableToTransformClass(e.getMessage());
        throw new HibernateException("Unable to transform class: " + e.getMessage(), e);
    } finally {
        try {
            out.close();
        } catch (IOException ignored) {
        }
    }
}
Also used : HibernateException(org.hibernate.HibernateException) DataOutputStream(java.io.DataOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) EnhancementException(org.hibernate.bytecode.enhance.spi.EnhancementException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) UncheckedIOException(java.io.UncheckedIOException) NotFoundException(javassist.NotFoundException) HibernateException(org.hibernate.HibernateException)

Aggregations

HibernateException (org.hibernate.HibernateException)609 Session (org.hibernate.Session)285 DAOException (com.tomasio.projects.trainning.exception.DAOException)186 DAOException (org.jbei.ice.storage.DAOException)122 ArrayList (java.util.ArrayList)63 Criteria (org.hibernate.Criteria)56 Test (org.junit.Test)43 Transaction (org.hibernate.Transaction)39 SQLException (java.sql.SQLException)38 SimpleDateFormat (java.text.SimpleDateFormat)22 Query (org.hibernate.Query)20 IOException (java.io.IOException)19 ParseException (java.text.ParseException)18 TestForIssue (org.hibernate.testing.TestForIssue)16 Date (java.util.Date)13 List (java.util.List)12 PersistenceException (org.mifos.framework.exceptions.PersistenceException)12 Serializable (java.io.Serializable)11 HashMap (java.util.HashMap)11 SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)11