como posso passar uma String onde um metodo Restrictions.eq
o segundo parametro pede um Object e estou passando em uma String
0 DocumentType.CPF (Enum)
e me da erro
org.hibernate.HibernateException: Exception while invoking identifierMethod ?number?of enumeration class ?lass br.com.data.model.user.DocumentType?
como poderia converter de String para Enum ???
String tipo = "DocumentType.CPF";
c.add(Restrictions.eq("document.type", tipo));
public class Documento {
@Id
@GeneratedValue
@Column(name = "DOCUMENT_ID")
private long id;
@Column(name = "document_type", columnDefinition="integer", nullable = true)
@Type(
type = "br.com.GenericEnumUserType",
parameters = {
@Parameter(
name = "enumClassName",
value = "br.com.DocumentType"),
@Parameter(
name = "identifierMethod",
value = "number"),
@Parameter(
name = "valueOfMethod",
value = "valueOf")
}
)
private DocumentType type;
-=--
public enum DocumentType {
CPF(0),
CNPJ(1),
RG(2),
PASSPORT(3),
TITULO(4),
RUT(5),
NIS(6),
CEI(7),
CEIPJ(8),
CITY_STATE_SUBSCRIPTION(9),
OTHER(10);
private final int number;
private DocumentType(int number){
this.number = number;
}
public int number(){
return number;
}
public static DocumentType valueOf(int id) {
switch (id) {
case 0: return CPF;
case 1: return CNPJ;
case 2: return RG;
case 3: return PASSPORT;
case 4: return TITULO;
case 5: return RUT;
case 6: return NIS;
case 7: return CEI;
case 8: return CEIPJ;
case 9: return CITY_STATE_SUBSCRIPTION;
default: return OTHER;
}
}
}