Search in sources :

Example 1 with AttributeConverterTypeAdapter

use of org.hibernate.type.descriptor.converter.AttributeConverterTypeAdapter in project hibernate-orm by hibernate.

the class AndLobTest method testMappingAttributeWithLobAndAttributeConverter.

@Test
public void testMappingAttributeWithLobAndAttributeConverter() {
    final Metadata metadata = new MetadataSources(ssr).addAnnotatedClass(EntityImpl.class).buildMetadata();
    final Type type = metadata.getEntityBinding(EntityImpl.class.getName()).getProperty("status").getType();
    final AttributeConverterTypeAdapter concreteType = assertTyping(AttributeConverterTypeAdapter.class, type);
    assertEquals(Types.BLOB, concreteType.getSqlTypeDescriptor().getSqlType());
}
Also used : Type(org.hibernate.type.Type) Metadata(org.hibernate.boot.Metadata) MetadataSources(org.hibernate.boot.MetadataSources) AttributeConverterTypeAdapter(org.hibernate.type.descriptor.converter.AttributeConverterTypeAdapter) Test(org.junit.Test)

Example 2 with AttributeConverterTypeAdapter

use of org.hibernate.type.descriptor.converter.AttributeConverterTypeAdapter in project hibernate-orm by hibernate.

the class LiteralNode method setExpectedType.

@Override
public void setExpectedType(Type expectedType) {
    if (this.expectedType != null) {
        return;
    }
    if (AttributeConverterTypeAdapter.class.isInstance(expectedType)) {
        final AttributeConverterTypeAdapter adapterType = (AttributeConverterTypeAdapter) expectedType;
        setText(determineConvertedValue(adapterType, getLiteralValue()));
        this.expectedType = expectedType;
    }
}
Also used : AttributeConverterTypeAdapter(org.hibernate.type.descriptor.converter.AttributeConverterTypeAdapter)

Example 3 with AttributeConverterTypeAdapter

use of org.hibernate.type.descriptor.converter.AttributeConverterTypeAdapter in project hibernate-orm by hibernate.

the class SimpleXmlOverriddenTest method baseline.

/**
 * A baseline test, with an explicit @Convert annotation that should be in effect
 */
@Test
public void baseline() {
    Metadata metadata = new MetadataSources(ssr).addAnnotatedClass(TheEntity.class).buildMetadata();
    PersistentClass pc = metadata.getEntityBinding(TheEntity.class.getName());
    Type type = pc.getProperty("it").getType();
    AttributeConverterTypeAdapter adapter = assertTyping(AttributeConverterTypeAdapter.class, type);
    assertTrue(SillyStringConverter.class.isAssignableFrom(adapter.getAttributeConverter().getConverterJavaTypeDescriptor().getJavaType()));
}
Also used : StringType(org.hibernate.type.StringType) Type(org.hibernate.type.Type) Metadata(org.hibernate.boot.Metadata) MetadataSources(org.hibernate.boot.MetadataSources) AttributeConverterTypeAdapter(org.hibernate.type.descriptor.converter.AttributeConverterTypeAdapter) PersistentClass(org.hibernate.mapping.PersistentClass) Test(org.junit.Test)

Example 4 with AttributeConverterTypeAdapter

use of org.hibernate.type.descriptor.converter.AttributeConverterTypeAdapter in project hibernate-orm by hibernate.

the class XmlWithExplicitConvertAnnotationsTest method testSimpleConvertUsage.

@Test
public void testSimpleConvertUsage() throws MalformedURLException {
    final EntityPersister ep = sessionFactory().getEntityPersister(Entity1.class.getName());
    final Type theDatePropertyType = ep.getPropertyType("theDate");
    final AttributeConverterTypeAdapter type = assertTyping(AttributeConverterTypeAdapter.class, theDatePropertyType);
    assertTrue(LongToDateConverter.class.isAssignableFrom(type.getAttributeConverter().getConverterJavaTypeDescriptor().getJavaType()));
    resetFlags();
    Session session = openSession();
    session.getTransaction().begin();
    session.persist(new Entity1(1, "1", new Date()));
    session.getTransaction().commit();
    session.close();
    assertTrue(convertToDatabaseColumnCalled);
    resetFlags();
    session = openSession();
    session.getTransaction().begin();
    session.get(Entity1.class, 1);
    session.getTransaction().commit();
    session.close();
    assertTrue(convertToEntityAttributeCalled);
    session = openSession();
    session.getTransaction().begin();
    session.createQuery("delete Entity1").executeUpdate();
    session.getTransaction().commit();
    session.close();
}
Also used : EntityPersister(org.hibernate.persister.entity.EntityPersister) Type(org.hibernate.type.Type) AttributeConverterTypeAdapter(org.hibernate.type.descriptor.converter.AttributeConverterTypeAdapter) Date(java.util.Date) Session(org.hibernate.Session) Test(org.junit.Test)

Example 5 with AttributeConverterTypeAdapter

use of org.hibernate.type.descriptor.converter.AttributeConverterTypeAdapter in project hibernate-orm by hibernate.

the class ParameterizedAttributeConverterParameterTypeTest method testNestedTypeParameterAutoApplication.

@Test
@TestForIssue(jiraKey = "HHH-10050")
public void testNestedTypeParameterAutoApplication() {
    final Metadata metadata = new MetadataSources(ssr).addAnnotatedClass(SampleEntity.class).getMetadataBuilder().applyAttributeConverter(IntegerListConverter.class).applyAttributeConverter(StringListConverter.class).build();
    // lets make sure the auto-apply converters were applied properly...
    PersistentClass pc = metadata.getEntityBinding(SampleEntity.class.getName());
    {
        Property prop = pc.getProperty("someStrings");
        AttributeConverterTypeAdapter type = assertTyping(AttributeConverterTypeAdapter.class, prop.getType());
        assertTrue(StringListConverter.class.isAssignableFrom(type.getAttributeConverter().getConverterJavaTypeDescriptor().getJavaType()));
    }
    {
        Property prop = pc.getProperty("someIntegers");
        AttributeConverterTypeAdapter type = assertTyping(AttributeConverterTypeAdapter.class, prop.getType());
        assertTrue(IntegerListConverter.class.isAssignableFrom(type.getAttributeConverter().getConverterJavaTypeDescriptor().getJavaType()));
    }
}
Also used : Metadata(org.hibernate.boot.Metadata) MetadataSources(org.hibernate.boot.MetadataSources) AttributeConverterTypeAdapter(org.hibernate.type.descriptor.converter.AttributeConverterTypeAdapter) Property(org.hibernate.mapping.Property) PersistentClass(org.hibernate.mapping.PersistentClass) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Aggregations

AttributeConverterTypeAdapter (org.hibernate.type.descriptor.converter.AttributeConverterTypeAdapter)15 Type (org.hibernate.type.Type)11 Test (org.junit.Test)11 EntityPersister (org.hibernate.persister.entity.EntityPersister)7 Session (org.hibernate.Session)6 MetadataSources (org.hibernate.boot.MetadataSources)5 PersistentClass (org.hibernate.mapping.PersistentClass)4 Metadata (org.hibernate.boot.Metadata)3 Property (org.hibernate.mapping.Property)3 URL (java.net.URL)2 Date (java.util.Date)2 StandardServiceRegistry (org.hibernate.boot.registry.StandardServiceRegistry)2 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)2 JpaAttributeConverter (org.hibernate.metamodel.model.convert.spi.JpaAttributeConverter)2 TestForIssue (org.hibernate.testing.TestForIssue)2 AttributeConverter (jakarta.persistence.AttributeConverter)1 Iterator (java.util.Iterator)1 LinkedHashMap (java.util.LinkedHashMap)1 Geometry (org.geolatte.geom.Geometry)1 QueryException (org.hibernate.QueryException)1