我第一次使用play From class object扩展泛型的模型。
当我尝试从请求绑定并将其分配给我的concret模型的Form时出现错误:
Form<Unit> filled_form = form(Unit.class).bindFromRequest();
我得到的错误:
[error] play - Cannot invoke the action, eventually got an error: javax.validation.ValidationException: HV000041: Call to TraversableResolver.isReachable() threw an exception.
stacktrace:
FORM TEST
[error] play - Cannot invoke the action, eventually got an error: javax.validation.ValidationException: HV000041: Call to TraversableResolver.isReachable() threw an exception.
[error] application -
! @6kb173m85 - Internal server error, for (POST) [/SupraADMIN/oddzialy/zapisz] ->
play.api.Application$$anon$1: Execution exception[[ValidationException: HV000041: Call to TraversableResolver.isReachable() threw an exception.]]
at play.api.Application$class.handleError(Application.scala:293) ~[play_2.10.jar:2.2.4]
at play.api.DefaultApplication.handleError(Application.scala:399) [play_2.10.jar:2.2.4]
at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$3$$anonfun$applyOrElse$3.apply(PlayDefaultUpstreamHandler.scala:264) [play_2.10.jar:2.2.4]
at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$3$$anonfun$applyOrElse$3.apply(PlayDefaultUpstreamHandler.scala:264) [play_2.10.jar:2.2.4]
at scala.Option.map(Option.scala:145) [scala-library.jar:na]
at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$3.applyOrElse(PlayDefaultUpstreamHandler.scala:264) [play_2.10.jar:2.2.4]
Caused by: javax.validation.ValidationException: HV000041: Call to TraversableResolver.isReachable() threw an exception.
at org.hibernate.validator.internal.engine.ValidatorImpl.isReachable(ValidatorImpl.java:1316) ~[hibernate-validator.jar:5.0.1.Final]
at org.hibernate.validator.internal.engine.ValidatorImpl.isValidationRequired(ValidatorImpl.java:1292) ~[hibernate-validator.jar:5.0.1.Final]
at org.hibernate.validator.internal.engine.ValidatorImpl.validateConstraint(ValidatorImpl.java:475) ~[hibernate-validator.jar:5.0.1.Final]
at org.hibernate.validator.internal.engine.ValidatorImpl.validateConstraintsForDefaultGroup(ValidatorImpl.java:424) ~[hibernate-validator.jar:5.0.1.Final]
at org.hibernate.validator.internal.engine.ValidatorImpl.validateConstraintsForCurrentGroup(ValidatorImpl.java:388) ~[hibernate-validator.jar:5.0.1.Final]
at org.hibernate.validator.internal.engine.ValidatorImpl.validateInContext(ValidatorImpl.java:340) ~[hibernate-validator.jar:5.0.1.Final]
Caused by: java.lang.NullPointerException: null
at models.Generic.hashCode(Generic.java:128) ~[na:na]
at org.hibernate.validator.internal.engine.resolver.SingleThreadCachedTraversableResolver$TraversableHolder.buildHashCode(SingleThreadCachedTraversableResolver.java:153) ~[hibernate-validator.jar:5.0.1.Final]
at org.hibernate.validator.internal.engine.resolver.SingleThreadCachedTraversableResolver$TraversableHolder.<init>(SingleThreadCachedTraversableResolver.java:114) ~[hibernate-validator.jar:5.0.1.Final]
at org.hibernate.validator.internal.engine.resolver.SingleThreadCachedTraversableResolver$TraversableHolder.<init>(SingleThreadCachedTraversableResolver.java:96) ~[hibernate-validator.jar:5.0.1.Final]
at org.hibernate.validator.internal.engine.resolver.SingleThreadCachedTraversableResolver.isReachable(SingleThreadCachedTraversableResolver.java:41) ~[hibernate-validator.jar:5.0.1.Final]
at org.hibernate.validator.internal.engine.ValidatorImpl.isReachable(ValidatorImpl.java:1307) ~[hibernate-validator.jar:5.0.1.Final]
[error] application - REGUEST: POST /SupraADMIN/oddzialy/zapisz GENERATED ERROR: @6kb173m85: Execution exception in /home/korbeldaniel/Aplikacje/Eclipse/SVP/modules/admin/app/controllers/CMS.java:472
这是我的控制器方法:
System.out.println("FORM TEST");
Form<Unit> filled_form = form(Unit.class).bindFromRequest();
System.out.println(filled_form);
if (filled_form.hasErrors()) {
List<Unit> unitsList = new Unit().getList();
return badRequest(views.html.CMS.UnitsAdd.render(unitsList,filled_form,new Unit().prepareJsonTree()));
} else {
filled_form.get().toDataBase();
flash("success", "Pomyślnie dodano.");
return redirect(routes.CMS.Units());
}
模特课:
@Entity
@Table(name="common__Unit")
public class Unit extends GenericDictionary<Unit> {
@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(name="parent_id")
public Unit parent;
由单元模型扩展的GenericDictionary模型:
@MappedSuperclass
public abstract class GenericDictionary<T extends Generic<T>> extends Generic<T> {
@Required
public String name;
@Required
public boolean active = true;
GenericDictionary模型扩展的Generic模型:
@MappedSuperclass
public abstract class Generic<T extends Generic> {
@Transient
public Class<T> entityClass;
Generic() {
entityClass = ((Class) ((Class) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0]));
}
@Id
@GeneratedValue(strategy = GenerationType.TABLE)
public Long id;
@ManyToOne(cascade = CascadeType.MERGE)
@Constraints.Required
public User creationUser;
请帮帮我。
答案 0 :(得分:0)
使用复杂类型层次结构时,getGenericSuperclass
方法不起作用。相反,您可以尝试使用TypeTools:
Generic() {
entityClass = (Class<T>)TypeResolver.resolveRawArgument(Generic.class, getClass());
}