简体   繁体   中英

Hibernate : String Index Out Of Bounds Exception

I have a column in a MySql table that is defined as char(1).That column is having an empty value (not null). When reading this in using Hibernate, it throws an exception:

java.lang.StringIndexOutOfBoundsException: String index out of range: 0 at java.lang.String.charAt(String.java:658)

This is my domain class of that table:

@Entity
@Table(name="ACTIONS",schema="IPLAN")
public class Actions
{
@Id
@GeneratedValue
@Column(name="ID")
private long id;

@Column(name="TOTAL_HOURS")
private int hours;

@Column(name="TYPE")
private char type;
//getters and setters
}

Update :

I 'am facing this problem after updating the table.The query used is:

update actions set type=''

Please help!

It seems its value is not blank.

Check if you have 'SPACE' instead of blank.

This issue due to character field in table for which you are using char as a data type so try changing char datatype to TinyInt(1) .

This might help you in deep understanding.

我有类似的问题能够通过使用长度= 1的字符串来修复它

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM