Unable to use fully qualified name of BasicAttribute after upgrade to 6

Hello,

after upgrading from hibernate 5 to hibernate 6.6.0.FINAL, the following query stopped working:

entityManager.createQuery("select t from EntityWithStatus t where t.status < org.hibernate.bugs.Status.ONE").getResultList()

and starts throwing an assertion error in org.hibernate.sql.ast.tree.expression.QueryLiteral#QueryLiteral.

Is this type of query no longer supported or a bug?

Thanks in advance!

For reference:

@Entity
public class EntityWithStatus {

    @Id
    @GeneratedValue
    private Long id;

    @Convert(converter = StatusConverter.class)
    private Status status;

    public Long getId() {
        return id;
    }

    public Status getStatus() {
        return status;
    }
}

public class Status implements Serializable {

    private static final Map<Integer, Status> VALUES = new HashMap<>();

    public static Status ONE = new Status(1);
    public static Status TWO = new Status(2);

    private final int value;

    Status(int value) {
        this.value = value;
        VALUES.put(value, this);
    }

    public int getValue() {
        return value;
    }

    public static Status from(int value) {
        return VALUES.get(value);
    }

    @Override
    public String toString() {
        return "Status{" + "value=" + value + '}';
    }
}
@Converter
public class StatusConverter implements AttributeConverter<Status, Integer> {

    @Override
    public Integer convertToDatabaseColumn(Status attribute) {
        return attribute == null ? null : attribute.getValue();
    }

    @Override
    public Status convertToEntityAttribute(Integer dbData) {
        return dbData == null ? null : Status.from(dbData);
    }
}

I’m surprised this used to work, but I don’t think this was an officially supported feature - you can see the types of literal expressions supported by Hibernate in this chapter of the user guide.

You should be able to make your query work by using a literal with the relational value corresponding to that Status, i.e. the result of passing it through the StatusConverter - which will be a simple integer.

thanks for the quick response! well, basically it is/was the same like working with an enum in hibernate 5.

You’re right, having the relational value directly in the query works. However, this means imho that the semantic in the query gets lost. It somehow feels strange, that you need to work directly with the database values here.
Btw, this even leads to a warning in my IDE here:

Moreover, passing the value as a query parameter also works.

entityManager.createQuery("select t from EntityWithStatus t where t.status < :status")
				.setParameter("status", org.hibernate.bugs.Status.ONE).getResultList()

Usually assertion errors mean something unexpected happened, so this might indeed be a bug (even though the “feature” was never documented). Feel free to create a reproducer with our test case template and if you are able to reproduce the issue, create a new ticket in our issue tracker and attach that reproducer.

ok, thanks again for your help. issue & reproducer is now created, I just didn’t want to spam the issue tracker before asking here. :grinning: