如何Spring JPA使用hibernate将String数组数据保存到数据库

时间:2014-11-25 12:57:59

标签: spring hibernate jpa

我是Spring的新手。尝试使用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;
}
}

我在mySQL中有一个表: -

CREATE TABLE PRODUCTORDER ( 
       id int(6) NOT NULL AUTO_INCREMENT, 
       name varchar(30) NOT NULL, 
       address varchar(50) NOT NULL, 
       items varchar(50) not null, 
       PRIMARY KEY(id)
  ) 
  ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8;

当我尝试保存数据时,我收到此错误: -

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

0 个答案:

没有答案