Reputation: 318
I am having some trouble figuring out why something is not working when trying to persist an object using Springs default Repositories. I am using hibernate as my persistence layer and Spring MVC framework. I use JPA instead of hibernate mapping files.
The error I am seeing is the following:
WARN : org.hibernate.util.JDBCExceptionReporter - SQL Error: 1366, SQLState: HY000
ERROR: org.hibernate.util.JDBCExceptionReporter - Incorrect integer value: '\xAC\xED\x00\x05sr\x00!com.kwhours.butternut.domain.Type\xCF;\xBF\xEF\x8A\x82\x87\xF1\x02\x00\x0DZ\x00\x06isLeafI\x00\x05levelL\' for column 'type_id' at row 1
I am trying to persist a domain object with JPA annotations the relevant part of that code is:
@Entity
@Table(name = "question")
public class Question implements java.io.Serializable {
private Type type;
@Column(name = "type_id")
public Type getType() {
return this.type;
}
public void setType(Type type) {
this.type = type;
}
}
I have a foreign key constraint properly set up on the question.type_id column to type.id column. I am able to have my objects all properly represented in code but when I try to make the following repository persist the object, I get the afore mentioned error.
public interface QuestionRepository extends CrudRepository<Question, Long> {
public List<Question> findByDatasetInstanceId(Long datasetInstanceId);
}
So to be clear. I can make a new question object and retrieve a type object from the db using a repository. I can set questions.type to this new type object but I get that error whenever I try to persist the question which contains that type using the repository above. I checked out the type object in the debugger and there seems to be nothing amiss with it. Any clues or suggestions are helpful. That looks like some kind of escape character sequence but I am not really sure.
Upvotes: 0
Views: 1942
Reputation: 318
So I was really silly about this. I am missing the proper annotations and it wasn't taking the type id out to insert but rather tryign to somehow insert this java object
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "type_id")
public Type getType() {
return this.type;
}
that code above solved the issue
Upvotes: 1