开发者

Hibernate ClassCastException when performing merge/ update of class that uses @ElementCollection with Enums

I have a class that gives the exception below when saving. This is puzzling because I can retrieve the data fine. The error still occurs even if I perform a merge / update on an entity I have retrieved (with making any changes).

ServerStatusException data: 
ASObject(26024375){message=java.lang.String cannot be cast to java.lang.Enum,
rootCause=ASObject(9663101){message=java.lang.String cannot be cast to
java.lang.Enum, localizedMessage=java.lang.String cannot be cast to
java.lang.Enum, cause=null}, details=java.lang.ClassCastException,
code=Server.Processing} HttpResponseInfo: HttpResponseInfo code: 200 message: OK

Here is the property definition:

@ElementCollection(targetClass=FilePrivilegeEnum.class, fetch=FetchType.EAGER)
@JoinTable(name="edrfiletyperoleprivilegelink开发者_开发知识库", joinColumns={@JoinColumn(name="file_type_role_id")})
@Column(name="privilege", nullable = false)
@Enumerated(EnumType.STRING)
private Set<FilePrivilegeEnum> privileges = new HashSet<FilePrivilegeEnum>();
public Set<FilePrivilegeEnum> getPrivileges() { return this.privileges; }
public void setPrivileges (Set<FilePrivilegeEnum> privileges) { this.privileges = privileges; }

And here is the privilege class:

public enum FilePrivilegeEnum { 
  FILE_VIEW,
  FILE_CREATE,
  FILE_AMEND,
  FILE_DELETE;
}


I think that replacing your @ElementCollection with the following will solve the problem:

@ElementCollection(targetClass=java.lang.String, fetch=FetchType.EAGER)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜