I am using Hibernate and got the exception ArrayIndexOutOfBoundsException. What are the possible causes?

- 30,738
- 21
- 105
- 131

- 21,385
- 10
- 35
- 34
-
1You tried to index an array... outside its bounds? – Amber Aug 16 '10 at 07:59
-
Must be something accessed a non existing index of some array! Thats all I can infer from your question – Gopi Aug 16 '10 at 07:59
-
ArrayIndexOutOfBoundsException can occur whenever you try to access an array element using an index which is either less than 0 or greater than the [array size-1]. Try to post the code to get clear answers. – chedine Aug 16 '10 at 08:02
-
show some code ? Look at the stacktrace to see which code you should show – Bozho Aug 16 '10 at 08:19
-
1See also http://stackoverflow.com/questions/5554734/what-causes-a-java-lang-arrayindexoutofboundsexception-and-how-do-i-prevent-it – Raedwald Mar 12 '15 at 13:51
-
I got this exception from Hibernate too. After restarting whole server, it gone. Maybe [@Testalonga's answer](https://stackoverflow.com/a/3492578/419348) is right. – AechoLiu Oct 29 '20 at 06:49
4 Answers
It's possible that Hibernate is throwing this exception in the case you use an old JDBC driver with Oracle. At some point there was a bug in the JDBC diver with the fetch-size, meaning that if the fetch-size you use in Hibernate (hibernate.properties or in hibernate.cfg.xml) was not the same as in jdbc-level, you got an ArrayIndexOutOfBoundsException.

- 30,738
- 21
- 105
- 131

- 91
- 1
You have tried to access an index which is out of your array size i.e. index < 0 or index >= array.length
.
For example int[] myArray = new int[10];
if you access myArray[11]
you will get ArrayIndexOutOfBoundsException

- 5,973
- 4
- 37
- 60
-
3Even if you access `myArray[10]` in that case you'll get an `ArrayIndexOutOfBoundsException`. – Jesper Aug 16 '10 at 08:06
-
Thanks Jesper I agree with you. whenever array index satisfies index < 0 or index >= array.length condition we will get ArrayIndexOutOfBoundsException – Upul Bandara Aug 16 '10 at 08:21
You access some index out of the array size. For example, myArray.get(-1);

- 18,639
- 11
- 76
- 110
You are indexing an array with an index out of the size of the Array. It has to do nothing with hibernate.
Check in your code that the index
variable is lower than array.size()

- 11,395
- 12
- 43
- 62