I'm beginner in Hibernate framework, and now I integrated Spring and Hibernate in one project. I ran it OK, but it have something I can't understand why. The problem is:
I have bean class decribed here :
@Entity
@Table(name = "Sample")
public class Sample {
private int id;
private String firstName;
private String lastName;
private String sex;
private String[] interests;
@Id
@GeneratedValue
@Column(name = "id")
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
@Column(name = "firstName")
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
@Column(name = "lastName")
public String getLastName() {
return lastName;
}
public void setSex(String sex) {
this.sex = sex;
}
@Column(name = "sex")
public String getSex() {
return sex;
}
public void setInterests(String[] interests) {
this.interests = interests;
}
@Column(name = "interests")
public String[] getInterests() {
return interests;
}
}
In this class, you see, I have interests field is array of string which showed as many of checkbox.
In DAO, when controller call to save object to database, I just use hibernateTemplate.saveOrUpdate(sample) class in Spring to persist object.
If database use default charset, it's OK, run and don't have any error but when I select table in database system, it show me a unreadable string, it's similar to ¬í ur [Ljava.lang.String;ÒVçé{G xp t Quidditcht Herbology . I think it's 'place holder' which Hibernate gave to split when I want to read and fill back in object.
But the problem is if database system use utf8 charset, it can't run, and throw exception similar to Incorrect string value: '\xAC\xED\x00\x05ur...' for column 'interests' at row 1
I think because that string is not supported in database with utf8 charset.
Any idea about that?
Thanks!