Fix problem when Hibernate on MySQL is confused to read back Enums from VARCHARs
It treated the single byte String with its ASCII values, which then didn't find a representation in the enum's values, which lead to a "ArrayIndexOutOfBoundsException: Index 48" for a value "0" (ASCII 48). This behavior changed when migrating from Hibernate 5 to Hibernate 6. Hibernate expects a TinyInt value for all Enums by default, and this annotation overrides it.
This commit is contained in:
parent
b7d5b6a135
commit
e00af7e172
2 changed files with 7 additions and 0 deletions
|
@ -41,7 +41,9 @@ import jakarta.persistence.UniqueConstraint;
|
||||||
import org.hibernate.annotations.BatchSize;
|
import org.hibernate.annotations.BatchSize;
|
||||||
import org.hibernate.annotations.Fetch;
|
import org.hibernate.annotations.Fetch;
|
||||||
import org.hibernate.annotations.FetchMode;
|
import org.hibernate.annotations.FetchMode;
|
||||||
|
import org.hibernate.annotations.JdbcType;
|
||||||
import org.hibernate.annotations.Nationalized;
|
import org.hibernate.annotations.Nationalized;
|
||||||
|
import org.hibernate.type.descriptor.jdbc.VarcharJdbcType;
|
||||||
import org.keycloak.representations.idm.authorization.DecisionStrategy;
|
import org.keycloak.representations.idm.authorization.DecisionStrategy;
|
||||||
import org.keycloak.representations.idm.authorization.Logic;
|
import org.keycloak.representations.idm.authorization.Logic;
|
||||||
|
|
||||||
|
@ -86,9 +88,11 @@ public class PolicyEntity {
|
||||||
private String type;
|
private String type;
|
||||||
|
|
||||||
@Column(name = "DECISION_STRATEGY")
|
@Column(name = "DECISION_STRATEGY")
|
||||||
|
@JdbcType(VarcharJdbcType.class)
|
||||||
private DecisionStrategy decisionStrategy = DecisionStrategy.UNANIMOUS;
|
private DecisionStrategy decisionStrategy = DecisionStrategy.UNANIMOUS;
|
||||||
|
|
||||||
@Column(name = "LOGIC")
|
@Column(name = "LOGIC")
|
||||||
|
@JdbcType(VarcharJdbcType.class)
|
||||||
private Logic logic = Logic.POSITIVE;
|
private Logic logic = Logic.POSITIVE;
|
||||||
|
|
||||||
@ElementCollection(fetch = FetchType.LAZY)
|
@ElementCollection(fetch = FetchType.LAZY)
|
||||||
|
|
|
@ -18,6 +18,8 @@
|
||||||
|
|
||||||
package org.keycloak.authorization.jpa.entities;
|
package org.keycloak.authorization.jpa.entities;
|
||||||
|
|
||||||
|
import org.hibernate.annotations.JdbcType;
|
||||||
|
import org.hibernate.type.descriptor.jdbc.VarcharJdbcType;
|
||||||
import org.keycloak.representations.idm.authorization.DecisionStrategy;
|
import org.keycloak.representations.idm.authorization.DecisionStrategy;
|
||||||
import org.keycloak.representations.idm.authorization.PolicyEnforcementMode;
|
import org.keycloak.representations.idm.authorization.PolicyEnforcementMode;
|
||||||
|
|
||||||
|
@ -41,6 +43,7 @@ public class ResourceServerEntity {
|
||||||
private boolean allowRemoteResourceManagement;
|
private boolean allowRemoteResourceManagement;
|
||||||
|
|
||||||
@Column(name = "POLICY_ENFORCE_MODE")
|
@Column(name = "POLICY_ENFORCE_MODE")
|
||||||
|
@JdbcType(VarcharJdbcType.class)
|
||||||
private PolicyEnforcementMode policyEnforcementMode = PolicyEnforcementMode.ENFORCING;
|
private PolicyEnforcementMode policyEnforcementMode = PolicyEnforcementMode.ENFORCING;
|
||||||
|
|
||||||
@Column(name = "DECISION_STRATEGY")
|
@Column(name = "DECISION_STRATEGY")
|
||||||
|
|
Loading…
Reference in a new issue