質問編集履歴

2

java.lang.IllegalArgumentExceptionの内容

2020/07/02 11:51

投稿

box_908
box_908

スコア5

test CHANGED
@@ -1 +1 @@
1
- era-Java実装 [java.lang.ClassCastException]を解消したいです。
1
+ era-Java実装 [java.lang.IllegalArgumentException]を解消したいです。
test CHANGED
@@ -2,9 +2,13 @@
2
2
 
3
3
  以下のエラーを解消したいです。
4
4
 
5
- java.lang.ClassCastException
5
+ java.lang.IllegalArgumentException
6
+
7
+
8
+
6
-
9
+ TypedQueryを使用して、SQL発行すると、
10
+
7
-
11
+ 上記のエラーが出力されます。
8
12
 
9
13
  すみませんが、ご教示お願い致します!
10
14
 
@@ -12,13 +16,19 @@
12
16
 
13
17
 
14
18
 
19
+
20
+
15
21
  エラーの詳細が下記となります・
16
22
 
17
23
  ```
18
24
 
19
- java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to todo.form.ConfirmForm
25
+ java.lang.IllegalArgumentException: Cannot create TypedQuery for query with more than one return using requested result type [todo.form.ConfirmForm]
26
+
20
-
27
+ at org.hibernate.internal.AbstractSharedSessionContract.resultClassChecking(AbstractSharedSessionContract.java:870) ~[hibernate-core-5.4.17.Final.jar:5.4.17.Final]
28
+
21
- at todo.controller.SanshoController.search(SanshoController.java:92) ~[classes/:na]
29
+ at org.hibernate.internal.AbstractSharedSessionContract.createQuery(AbstractSharedSessionContract.java:817) ~[hibernate-core-5.4.17.Final.jar:5.4.17.Final]
30
+
31
+ at org.hibernate.internal.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:23) ~[hibernate-core-5.4.17.Final.jar:5.4.17.Final]
22
32
 
23
33
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_181]
24
34
 
@@ -28,6 +38,34 @@
28
38
 
29
39
  at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_181]
30
40
 
41
+ at org.springframework.orm.jpa.ExtendedEntityManagerCreator$ExtendedEntityManagerInvocationHandler.invoke(ExtendedEntityManagerCreator.java:366) ~[spring-orm-5.2.7.RELEASE.jar:5.2.7.RELEASE]
42
+
43
+ at com.sun.proxy.$Proxy68.createQuery(Unknown Source) ~[na:na]
44
+
45
+ at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_181]
46
+
47
+ at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_181]
48
+
49
+ at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_181]
50
+
51
+ at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_181]
52
+
53
+ at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:314) ~[spring-orm-5.2.7.RELEASE.jar:5.2.7.RELEASE]
54
+
55
+ at com.sun.proxy.$Proxy68.createQuery(Unknown Source) ~[na:na]
56
+
57
+ at todo.service.IsCheakService.oldSelect(IsCheakService.java:37) ~[classes/:na]
58
+
59
+ at todo.controller.SanshoController.search(SanshoController.java:87) ~[classes/:na]
60
+
61
+ at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_181]
62
+
63
+ at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_181]
64
+
65
+ at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_181]
66
+
67
+ at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_181]
68
+
31
69
  at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:190) ~[spring-web-5.2.7.RELEASE.jar:5.2.7.RELEASE]
32
70
 
33
71
  at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:138) ~[spring-web-5.2.7.RELEASE.jar:5.2.7.RELEASE]
@@ -100,25 +138,7 @@
100
138
 
101
139
  at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74) [tomcat-embed-core-9.0.36.jar:9.0.36]
102
140
 
103
- at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343) [tomcat-embed-core-9.0.36.jar:9.0.36]
141
+ at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343) [tomcat-embed-
104
-
105
- at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:373) [tomcat-embed-core-9.0.36.jar:9.0.36]
106
-
107
- at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65) [tomcat-embed-core-9.0.36.jar:9.0.36]
108
-
109
- at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868) [tomcat-embed-core-9.0.36.jar:9.0.36]
110
-
111
- at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1590) [tomcat-embed-core-9.0.36.jar:9.0.36]
112
-
113
- at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) [tomcat-embed-core-9.0.36.jar:9.0.36]
114
-
115
- at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [na:1.8.0_181]
116
-
117
- at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [na:1.8.0_181]
118
-
119
- at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-9.0.36.jar:9.0.36]
120
-
121
- at java.lang.Thread.run(Thread.java:748) [na:1.8.0_181]
122
142
 
123
143
 
124
144
 
@@ -146,16 +166,8 @@
146
166
 
147
167
  private String idName;
148
168
 
149
-
150
-
151
-
152
-
153
169
  public ConfirmForm() {}
154
170
 
155
-
156
-
157
-
158
-
159
171
  public String getId() {
160
172
 
161
173
  return id;
@@ -164,8 +176,6 @@
164
176
 
165
177
 
166
178
 
167
-
168
-
169
179
  public void setId(String id) {
170
180
 
171
181
  this.id = id;
@@ -248,7 +258,7 @@
248
258
 
249
259
 
250
260
 
251
- @Autowired
261
+ @PersistenceContext
252
262
 
253
263
  private EntityManager entityManager;
254
264
 
@@ -262,35 +272,35 @@
262
272
 
263
273
 
264
274
 
265
-
266
-
267
- @SuppressWarnings("unchecked")
268
-
269
- public List<ConfirmForm> oldSelect(String btn_id){
275
+ public List<ConfirmForm> oldSelect(String btn_id){
270
-
271
-
272
-
273
- StringBuilder sql = new StringBuilder();
276
+
274
-
277
+
278
+
279
+
280
+
281
+
282
+
283
+
284
+
285
+
286
+
287
+
288
+
275
- sql.append("select distinct d.id , d.name from Dd d, Sansho s where d.id = s.sanshoPK.gnbttype and ");
289
+ String jpql = "select distinct d.id , d.name from Dd d, Sansho s where d.id = s.sanshoPK.gnbttype and s.sanshoPK.btn_id = :btn_id";
276
-
277
-
278
-
279
-
280
-
281
- sql.append("s.sanshoPK.btn_id = :btn_id");
290
+
282
-
283
-
284
-
285
-
286
-
291
+
292
+
293
+
294
+
295
+
296
+
287
- Query query = entityManager.createQuery(sql.toString());
297
+ TypedQuery<ConfirmForm> query = entityManager.createQuery(jpql, ConfirmForm.class);
288
-
289
-
290
-
298
+
299
+
300
+
291
- query.setParameter("btn_id", btn_id);
301
+ query.setParameter("btn_id", btn_id)
292
-
302
+
293
- return query.getResultList();
303
+ return query.getResultList();
294
304
 
295
305
  }
296
306
 
@@ -340,10 +350,6 @@
340
350
 
341
351
  }
342
352
 
343
-
344
-
345
-
346
-
347
353
  }
348
354
 
349
355
  ```
@@ -358,22 +364,8 @@
358
364
 
359
365
  //SQL取得結果を同じ型のConfirmFormに詰める
360
366
 
367
+ //ここでエラー【java.lang.IllegalArgumentException】
368
+
361
369
  List<ConfirmForm> oldSns = isCheakService.oldSelect(btn_id);
362
370
 
363
-
364
-
365
- List<String> str = new ArrayList<>();
366
-
367
- for(int i=0; i<oldSns.size(); i++) {
368
-
369
-
370
-
371
- //ここでエラー【java.lang.ClassCastException】
372
-
373
- //同じ型ConfirmForm に入れているのに、「java.lang.ClassCastException」が発生します。
374
-
375
- ConfirmForm oldsns = oldSns.get(i);
376
-
377
-
378
-
379
- ```
371
+ ```

1

エラー詳細

2020/07/02 11:51

投稿

box_908
box_908

スコア5

test CHANGED
@@ -1 +1 @@
1
- Java実装 [java.lang.ClassCastException]を解消したいです。
1
+ era-Java実装 [java.lang.ClassCastException]を解消したいです。
test CHANGED
@@ -10,6 +10,122 @@
10
10
 
11
11
 
12
12
 
13
+
14
+
15
+ エラーの詳細が下記となります・
16
+
17
+ ```
18
+
19
+ java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to todo.form.ConfirmForm
20
+
21
+ at todo.controller.SanshoController.search(SanshoController.java:92) ~[classes/:na]
22
+
23
+ at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_181]
24
+
25
+ at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_181]
26
+
27
+ at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_181]
28
+
29
+ at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_181]
30
+
31
+ at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:190) ~[spring-web-5.2.7.RELEASE.jar:5.2.7.RELEASE]
32
+
33
+ at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:138) ~[spring-web-5.2.7.RELEASE.jar:5.2.7.RELEASE]
34
+
35
+ at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:105) ~[spring-webmvc-5.2.7.RELEASE.jar:5.2.7.RELEASE]
36
+
37
+ at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:879) ~[spring-webmvc-5.2.7.RELEASE.jar:5.2.7.RELEASE]
38
+
39
+ at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:793) ~[spring-webmvc-5.2.7.RELEASE.jar:5.2.7.RELEASE]
40
+
41
+ at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87) ~[spring-webmvc-5.2.7.RELEASE.jar:5.2.7.RELEASE]
42
+
43
+ at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1040) ~[spring-webmvc-5.2.7.RELEASE.jar:5.2.7.RELEASE]
44
+
45
+ at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:943) ~[spring-webmvc-5.2.7.RELEASE.jar:5.2.7.RELEASE]
46
+
47
+ at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006) ~[spring-webmvc-5.2.7.RELEASE.jar:5.2.7.RELEASE]
48
+
49
+ at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:909) ~[spring-webmvc-5.2.7.RELEASE.jar:5.2.7.RELEASE]
50
+
51
+ at javax.servlet.http.HttpServlet.service(HttpServlet.java:660) ~[tomcat-embed-core-9.0.36.jar:9.0.36]
52
+
53
+ at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883) ~[spring-webmvc-5.2.7.RELEASE.jar:5.2.7.RELEASE]
54
+
55
+ at javax.servlet.http.HttpServlet.service(HttpServlet.java:741) ~[tomcat-embed-core-9.0.36.jar:9.0.36]
56
+
57
+ at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) ~[tomcat-embed-core-9.0.36.jar:9.0.36]
58
+
59
+ at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.36.jar:9.0.36]
60
+
61
+ at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) ~[tomcat-embed-websocket-9.0.36.jar:9.0.36]
62
+
63
+ at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.36.jar:9.0.36]
64
+
65
+ at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.36.jar:9.0.36]
66
+
67
+ at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100) ~[spring-web-5.2.7.RELEASE.jar:5.2.7.RELEASE]
68
+
69
+ at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) ~[spring-web-5.2.7.RELEASE.jar:5.2.7.RELEASE]
70
+
71
+ at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.36.jar:9.0.36]
72
+
73
+ at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.36.jar:9.0.36]
74
+
75
+ at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93) ~[spring-web-5.2.7.RELEASE.jar:5.2.7.RELEASE]
76
+
77
+ at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) ~[spring-web-5.2.7.RELEASE.jar:5.2.7.RELEASE]
78
+
79
+ at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.36.jar:9.0.36]
80
+
81
+ at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.36.jar:9.0.36]
82
+
83
+ at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201) ~[spring-web-5.2.7.RELEASE.jar:5.2.7.RELEASE]
84
+
85
+ at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) ~[spring-web-5.2.7.RELEASE.jar:5.2.7.RELEASE]
86
+
87
+ at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.36.jar:9.0.36]
88
+
89
+ at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.36.jar:9.0.36]
90
+
91
+ at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202) ~[tomcat-embed-core-9.0.36.jar:9.0.36]
92
+
93
+ at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) [tomcat-embed-core-9.0.36.jar:9.0.36]
94
+
95
+ at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:541) [tomcat-embed-core-9.0.36.jar:9.0.36]
96
+
97
+ at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139) [tomcat-embed-core-9.0.36.jar:9.0.36]
98
+
99
+ at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92) [tomcat-embed-core-9.0.36.jar:9.0.36]
100
+
101
+ at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74) [tomcat-embed-core-9.0.36.jar:9.0.36]
102
+
103
+ at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343) [tomcat-embed-core-9.0.36.jar:9.0.36]
104
+
105
+ at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:373) [tomcat-embed-core-9.0.36.jar:9.0.36]
106
+
107
+ at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65) [tomcat-embed-core-9.0.36.jar:9.0.36]
108
+
109
+ at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868) [tomcat-embed-core-9.0.36.jar:9.0.36]
110
+
111
+ at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1590) [tomcat-embed-core-9.0.36.jar:9.0.36]
112
+
113
+ at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) [tomcat-embed-core-9.0.36.jar:9.0.36]
114
+
115
+ at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [na:1.8.0_181]
116
+
117
+ at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [na:1.8.0_181]
118
+
119
+ at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-9.0.36.jar:9.0.36]
120
+
121
+ at java.lang.Thread.run(Thread.java:748) [na:1.8.0_181]
122
+
123
+
124
+
125
+ ```
126
+
127
+
128
+
13
129
  #該当ソースファイル
14
130
 
15
131