Search in sources :

Example 1 with SerializableType

use of org.hibernate.type.SerializableType in project hibernate-orm by hibernate.

the class QueryParameterBindingsImpl method collectPositionalBindTypes.

/**
	 * @deprecated (since 5.2) expect a different approach to org.hibernate.engine.spi.QueryParameters in 6.0
	 */
@Deprecated
public Type[] collectPositionalBindTypes() {
    Type[] types = new Type[positionalParameterBindings.size()];
    for (Map.Entry<Integer, QueryParameterBinding> entry : positionalParameterBindings.entrySet()) {
        final int position = entry.getKey();
        Type type = entry.getValue().getBindType();
        if (type == null) {
            log.debugf("Binding for positional-parameter [%s] did not define type, using SerializableType", position);
            type = SerializableType.INSTANCE;
        }
        types[position] = type;
    }
    return types;
}
Also used : SerializableType(org.hibernate.type.SerializableType) Type(org.hibernate.type.Type) QueryParameterBinding(org.hibernate.query.spi.QueryParameterBinding) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap)

Example 2 with SerializableType

use of org.hibernate.type.SerializableType in project hibernate-orm by hibernate.

the class Java8DateTimeTests method basicTests.

@Test
public void basicTests() {
    final PersistentClass entityBinding = metadata().getEntityBinding(TheEntity.class.getName());
    final Iterator propertyBindingIterator = entityBinding.getPropertyClosureIterator();
    while (propertyBindingIterator.hasNext()) {
        final Property propertyBinding = (Property) propertyBindingIterator.next();
        assertFalse("Found property bound as Serializable : " + propertyBinding.getName(), propertyBinding.getType() instanceof SerializableType);
    }
    TheEntity theEntity = new TheEntity(1);
    Session s = openSession();
    s.beginTransaction();
    s.save(theEntity);
    s.getTransaction().commit();
    s.close();
    s = openSession();
    s.beginTransaction();
    theEntity = (TheEntity) s.get(TheEntity.class, 1);
    dump(entityBinding, theEntity);
    assertNotNull(theEntity);
    s.delete(theEntity);
    s.getTransaction().commit();
    s.close();
}
Also used : SerializableType(org.hibernate.type.SerializableType) Iterator(java.util.Iterator) Property(org.hibernate.mapping.Property) PersistentClass(org.hibernate.mapping.PersistentClass) Session(org.hibernate.Session) Test(org.junit.Test)

Example 3 with SerializableType

use of org.hibernate.type.SerializableType in project hibernate-orm by hibernate.

the class SessionFactoryImpl method resolveParameterBindType.

@Override
public Type resolveParameterBindType(Class clazz) {
    String typename = clazz.getName();
    Type type = getTypeResolver().heuristicType(typename);
    boolean serializable = type != null && type instanceof SerializableType;
    if (type == null || serializable) {
        try {
            getMetamodel().entityPersister(clazz.getName());
        } catch (MappingException me) {
            if (serializable) {
                return type;
            } else {
                throw new HibernateException("Could not determine a type for class: " + typename);
            }
        }
        return getTypeHelper().entity(clazz);
    } else {
        return type;
    }
}
Also used : SerializableType(org.hibernate.type.SerializableType) SynchronizationType(javax.persistence.SynchronizationType) EventType(org.hibernate.event.spi.EventType) PersistenceContextType(javax.persistence.PersistenceContextType) PersistenceUnitTransactionType(javax.persistence.spi.PersistenceUnitTransactionType) Type(org.hibernate.type.Type) SerializableType(org.hibernate.type.SerializableType) HibernateException(org.hibernate.HibernateException) MappingException(org.hibernate.MappingException)

Aggregations

SerializableType (org.hibernate.type.SerializableType)3 Type (org.hibernate.type.Type)2 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 PersistenceContextType (javax.persistence.PersistenceContextType)1 SynchronizationType (javax.persistence.SynchronizationType)1 PersistenceUnitTransactionType (javax.persistence.spi.PersistenceUnitTransactionType)1 HibernateException (org.hibernate.HibernateException)1 MappingException (org.hibernate.MappingException)1 Session (org.hibernate.Session)1 EventType (org.hibernate.event.spi.EventType)1 PersistentClass (org.hibernate.mapping.PersistentClass)1 Property (org.hibernate.mapping.Property)1 QueryParameterBinding (org.hibernate.query.spi.QueryParameterBinding)1 Test (org.junit.Test)1