Issues with Open JPA with @Convert and @Converter - field not being recognized

55 views Asked by At

I am having a lot of difficulties getting @Convert and @Converter using Open JPA.

some_field is a longtext field in the database

@Entity
@Table(name = "basic")
public class Basic {

    @Column(name = "some_field")
    @Lob
    @Convert(converter = SomeFieldConverter.class)
    private SomeField someField;
...
}

@Converter
public class SomeFieldConverter implements AttributeConverter<SomeField, String> {
...
}

However, it seems like JPA is completely ignoring SomeField.

Debugging through the code during JPA initialization, in AnnotationPersistenceMetaDataParser when it tries to get a PersistenceStrategy from that column, it return null. This is because it's reading SomeField as an object, and since it's not an enum object it has no persistence strategy. This causes it not get added to declared fields, and essentially ignored.

I can get past this by marking it as @Basic as that manually assigns a persistence strategy. No examples show this being required. Is there a way to do this without this annotation? Why is this annotation required?

But even when it's recognized I run into the following issue: CannotCreateTransactionException ... Basic.someField declares a column that is not compatible with the expected type "blob".

I can get around this by marking the field as longblob instead of longtext, but I'd rather avoid DB changes. Is there a way to make this work keeping it as longtext? Or do I have to make it longblob? Why is this a requirement for this to work?

0

There are 0 answers