Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用hibernate将Spring JPA字符串数组数据保存到数据库_Spring_Hibernate_Jpa - Fatal编程技术网

如何使用hibernate将Spring JPA字符串数组数据保存到数据库

如何使用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

我是春天的新手。尝试使用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[] 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