Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AttributeConverter fails after migration from glassfish 4 to wildfly 8.1

I have an entity:

import java.io.Serializable;
import javax.persistence.*;
import java.util.List;

@Entity
@Table(name="user")
@NamedQuery(name="User.findAll", query="SELECT u FROM User u")
public class User implements Serializable {
    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    @Column(unique=true, nullable=false)
    private int id;

    @Column(nullable=false)
    private boolean aktiv;
...
}

and a Converter:

import javax.persistence.AttributeConverter;
import javax.persistence.Converter;

@Converter(autoApply = true)
public class BooleanConverter implements AttributeConverter<Boolean, Byte> {

    @Override
    public Byte convertToDatabaseColumn(Boolean value) {
        if (value) {
            return 1;
        } else {
            return 0;
        }
    }

    @Override
    public Boolean convertToEntityAttribute(Byte value) {
        return 1 == value.byteValue();
    }

}

This works fine with glassfish 4.0.

But on wildfly 8.1 the same code produces:

javax.persistence.PersistenceException: org.hibernate.HibernateException: Unknown wrap conversion requested: [B to java.lang.Byte
    at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1763)

(If I remove the "aktiv" column it works.)

Any idea what the problem is?

like image 936
Matthias Avatar asked Feb 11 '23 19:02

Matthias


1 Answers

Works if Byte is replaced with Integer. MySql's 'tinyint' is mapped with byte by default. The AttributeConverter also works as AttributeConverter<Boolean, Integer>

like image 120
Matthias Avatar answered Apr 07 '23 14:04

Matthias