我试图为我的小项目设置一些数据结构,但我面临着奇怪的问题。我在这里:
@Entity
@Table(name = "INTERVIEWS")
@Data
public class Interview implements Serializable {
@ManyToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
@JoinTable(name = "interviewers_interviews", joinColumns = {
@JoinColumn(name = "interviewer_id", referencedColumnName = "id")},
inverseJoinColumns = {@JoinColumn(name = "interview_id", referencedColumnName = "id")})
private Set<Interviewer> interviewers;
@Id
@GeneratedValue(strategy = IDENTITY)
@Column(name = "id", unique = true)
@NotEmpty
private Long id;
@Column(name = "date")
private Date date;
}
@Entity
@Table(name = "INTERVIEWERS")
@Data
public class Interviewer implements Serializable {
@ManyToMany(fetch = FetchType.EAGER, mappedBy = "interviewers")
private Set<Interview> interviews;
@Id
@GeneratedValue(strategy = IDENTITY)
@Column(name = "id", unique = true)
@NotEmpty
private Long id;
@Column(name = "first_name")
@NotEmpty
@Size(max = 128)
private String firstName;
@Column(name = "last_name")
@NotEmpty
@Size(max = 128)
private String lastName;
@Column(name = "email")
@Email
@NotEmpty
private String email;
@Column(name = "comment")
private String comment;
@Column(name = "technologies")
private String technologies;
@Column(name = "location")
private String location;
}
@Repository
public interface InterviewRepository extends JpaRepository<Interview, Long> {
Interview findById(long id);
Interview findByDate(Date date);
Set<Interview> findByDateBetween(Date startDate, Date endDate);
}
@Repository
public interface InterviewerRepository extends JpaRepository<Interviewer, Long>{
Interviewer findById(long id);
Interviewer findByFirstName(String firstName);
Interviewer findByLastName(String lastName);
List<Interviewer> findAll();
Interviewer findByLocation(String location);
Interviewer findByEmail(String email);
Interviewer deleteById(Long id);
}
我通过控制器中的映射方法执行请求,触发List<Interviewer> list = interviewerService.findAll();
我一直工作直到我添加了多对多的关系
但是当我尝试执行请求时,我会看到下一个错误:
输入例外报告
消息无法处理传入的事件&#39; [QUIET] [system.out] java.lang.RuntimeException:无法处理传入的事件 &#39; [ERROR] [org.apache.catalina.core.ContainerBase [Tomcat的]。[本地主机]。[/]。[调度]] Servlet [dispatcher]的Servlet.service()与path []的上下文 抛出异常[请求处理失败;嵌套异常是 java.lang.RuntimeException:无法处理传入的事件&#39; [ERROR]
description服务器遇到阻止它的内部错误 完成此请求。
例外
java.lang.RuntimeException:无法处理传入的事件&#39; [QUIET] [system.out] java.lang.RuntimeException:无法处理 来电事件&#39; [错误] [org.apache.catalina.core.ContainerBase [Tomcat的]。[本地主机]。[/]。[调度]] Servlet [dispatcher]的Servlet.service()与path []的上下文 抛出异常[请求处理失败;嵌套异常是 java.lang.RuntimeException:无法处理传入的事件&#39; [ERROR] [system.err] 22413 [http-bio-8080-exec-1] INFO com.luxoft.hiring.portal.controller.InterviewerController - 获取计数 适用于身份证号码为1&#39; (StyledTextOutputEvent) org.gradle.logging.internal.ConsoleBackedProgressRenderer.onOutput(ConsoleBackedProgressRenderer.java:50) sun.reflect.GeneratedMethodAccessor4.invoke(未知来源) sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) java.lang.reflect.Method.invoke(Method.java:483) org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35) org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24) org.gradle.internal.event.BroadcastDispatch.dispatch(BroadcastDispatch.java:87) org.gradle.internal.event.BroadcastDispatch.dispatch(BroadcastDispatch.java:31) org.gradle.messaging.dispatch.ProxyDispatchAdapter $ DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:93) com.sun.proxy。$ Proxy0.onOutput(Unknown Source) org.gradle.logging.internal.OutputEventRenderer.onOutput(OutputEventRenderer.java:250) org.gradle.logging.internal.TextStreamOutputEventListener.onTextEvent(TextStreamOutputEventListener.java:52) org.gradle.logging.internal.TextStreamOutputEventListener.onOutput(TextStreamOutputEventListener.java:36) org.gradle.logging.internal.PrintStreamLoggingSystem $ OutputEventDestination.onOutput(PrintStreamLoggingSystem.java:141) org.gradle.logging.internal.PrintStreamLoggingSystem $ 1.text(PrintStreamLoggingSystem.java:37) org.gradle.util.LineBufferingOutputStream.flush(LineBufferingOutputStream.java:102) org.gradle.util.LineBufferingOutputStream.write(LineBufferingOutputStream.java:84) java.io.OutputStream.write(OutputStream.java:116) java.io.PrintStream.write(PrintStream.java:480) sun.nio.cs.StreamEncoder.writeBytes(StreamEncoder.java:221) sun.nio.cs.StreamEncoder.implFlushBuffer(StreamEncoder.java:291) sun.nio.cs.StreamEncoder.flushBuffer(StreamEncoder.java:104) java.io.OutputStreamWriter.flushBuffer(OutputStreamWriter.java:185) java.io.PrintStream.write(PrintStream.java:527) java.io.PrintStream.print(PrintStream.java:669) java.io.PrintStream.println(PrintStream.java:823) org.gradle.util.LinePerThreadBufferingOutputStream.println(LinePerThreadBufferingOutputStream.java:194) java.lang.Throwable的$ WrappedPrintStream.println(Throwable.java:748) java.lang.Throwable.printStackTrace(Throwable.java:655) java.lang.Throwable.printStackTrace(Throwable.java:643) org.gradle.logging.internal.slf4j.OutputEventListenerBackedLogger.log(OutputEventListenerBackedLogger.java:135) org.gradle.logging.internal.slf4j.OutputEventListenerBackedLogger.error(OutputEventListenerBackedLogger.java:439) org.slf4j.bridge.SLF4JBridgeHandler.callPlainSLF4JLogger(SLF4JBridgeHandler.java:239) org.slf4j.bridge.SLF4JBridgeHandler.publish(SLF4JBridgeHandler.java:303) java.util.logging.Logger.log(Logger.java:738) java.util.logging.Logger.doLog(Logger.java:765) java.util.logging.Logger.logp(Logger.java:1041) org.apache.juli.logging.DirectJDKLog.log(DirectJDKLog.java:185) org.apache.juli.logging.DirectJDKLog.error(DirectJDKLog.java:151) org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501) org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98) org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408) org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040) org.apache.coyote.AbstractProtocol $ AbstractConnectionHandler.process(AbstractProtocol.java:607) org.apache.tomcat.util.net.JIoEndpoint $ SocketProcessor.run(JIoEndpoint.java:315) java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) java.util.concurrent.ThreadPoolExecutor中的$ Worker.run(ThreadPoolExecutor.java:617) java.lang.Thread.run(Thread.java:745)根本原因
java.lang.ArrayIndexOutOfBoundsException
但我不明白为什么它与TheArrayIndexOutOfBoundsException相关
在tomcat控制台中没有错误,我只看到下一个:Hibernate:选择interviewe0_.interviewer_id为intervie1_3_0_, interviewe0_.interview_id as intervie2_3_0_,interviewe1_.id as id1_2_1_,intervi ewe1_.comment为comment2_2_1_,interviewe1_.email 作为email3_2_1_,interviewe1_.first_name为first_na4_2_1_, interviewe1_.last_name为last_nam5_ 2_1_,interviewe1_.location为 location6_2_1_,interviewe1_.technologies as technolo7_2_1_ from interviewers_interviews interviewe0_ inner join IN TERVIEWERS interviewe1_在interviewe0_.interview_id = interviewe1_.id在哪里 interviewe0_.interviewer_id =?休眠:选择 interview0_.interview_id as intervie2_3_0_, interview0_.interviewer_id as intervie1_3_0_,interview1_.id as id1_4_1_,intervie w1_.date,作为来自interviewers_interviews的date2_4_1_ interview0_ inner join INTERVIEWS interview1_ on interview0_.interviewer_id = interview1_.id在这里 interviews0_.interview_id =?
答案 0 :(得分:0)
我遇到了一个非常相似的问题,并且从ArrayIndexOutOfBoundsException变得毫无意义。
@Data
@Entity
public class Identity implements IEntity<Integer> {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
@Column(unique = true, nullable = false)
private String username;
@Column(unique = true, nullable = false)
private String email;
@Column(nullable = false)
private String password;
@Column(nullable = false)
private Role role;
@ToString.Exclude
@OneToOne(mappedBy = "identity", cascade = CascadeType.ALL)
private Person person;
}
public enum Role implements GrantedAuthority {
SYSTEM, ADMIN, USER;
@Override
public String getAuthority() {
return name();
}
}
在data.sql中发现错误的插入语句。罪魁祸首。
INSERT INTO identity (id, email, password, username, role)
VALUES (4, 'anni_mueller@gmail.com',
'$2y$10$pzgIR0QYo.WyCGnAa9lr4eYC25aO4iFsi/WUzYjwBYDe9iyKZgvf2',
'anni', 3);
Role枚举只有3个值,因此可能的索引值范围从0到2。但是在SQL中,我插入了一个值为3的角色。这就是当我将此实体提取为时得到ArrayIndexOutOfBoundsException的原因JPA尝试映射Role索引3(不存在)。