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?
Works if Byte is replaced with Integer.
MySql's 'tinyint' is mapped with byte by default.
The AttributeConverter also works as AttributeConverter<Boolean, Integer>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With