0

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.

3
  • stackoverflow.com/questions/2762416/… Commented Oct 19, 2012 at 1:58
  • It's hanging trying to insert the id of the type object, is a Java Long and a Bigint(20) in the database. There is no string that has been encoded incorrectly here and that id is created because of the databases autoincrement so I doubt mysql is creating ids in an encoding it can not read :). Commented Oct 19, 2012 at 4:33
  • Please also post you Type class. Commented Oct 19, 2012 at 8:17

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

1 Comment

That was what I thought. I think it would also work if the Type entity was properly declined. That's why I wanted to see it ;-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.