如何使用hibernate将Spring JPA字符串数组数据保存到数据库
我是春天的新手。尝试使用JPA将以下模型保存到mysql如何使用hibernate将Spring JPA字符串数组数据保存到数据库,spring,hibernate,jpa,Spring,Hibernate,Jpa,我是春天的新手。尝试使用JPA将以下模型保存到mysql @Table(name = "PRODUCTORDER") public class Order extends AbstractPersistable<Long> { @Length(min = 4, max = 30) private String name; @Length(min = 4, max = 50) private String address; @NotEmpty private String[] ite
@Table(name = "PRODUCTORDER")
public class Order extends AbstractPersistable<Long> {
@Length(min = 4, max = 30)
private String name;
@Length(min = 4, max = 50)
private String address;
@NotEmpty
private String[] items; // error for this
// only items setter and getter shown
public String[] getItems() {
return items;
}
public void setItems(String[] items) {
this.items = items;
}
}
当我试图保存数据时,出现以下错误:-
org.springframework.orm.jpa.JpaSystemException:
org.hibernate.exception.GenericJDBCException: Incorrect string value: '\xAC\xED
\x00\x05ur...' for column 'items' at row 1; nested exception is
javax.persistence.PersistenceException:org.hibernate.exception.GenericJDBCException:
Incorrect string value: '\xAC\xED\x00\x05ur...' for column 'items' at row 1
这个不正确的字符串值是什么:'\xAC\xED\x00\x05ur…'。你能解释一下吗。你如何将字符串数组存储到单个varchar列中?您需要两个表和对应的两个实体,具有OneToMany关联。重新定义您的架构,使用规范化的表,然后使用jpa。这就是我在控制器中初始化字符串[]项的方式@ModelAttributeitems公共列表getItems{return Arrays.asListPorkkana、Kaali、Virtahepo;}
org.springframework.orm.jpa.JpaSystemException:
org.hibernate.exception.GenericJDBCException: Incorrect string value: '\xAC\xED
\x00\x05ur...' for column 'items' at row 1; nested exception is
javax.persistence.PersistenceException:org.hibernate.exception.GenericJDBCException:
Incorrect string value: '\xAC\xED\x00\x05ur...' for column 'items' at row 1