1. java
  2. android
  3. c#
  4. .net
  5. javascript
  6. php
  7. jquery
  8. html
  9. sql

Erro could not load an entity e wrong data type: java.lang.NumberFormatException

olá pessoal estou com os seguintes erros ao persistir uma um entidade com chave composta.

2014-02-13T23:35:34.399-0200|INFO: could not bind value '2c6d8085f3f2809ee2f2aee3efedaee4e5f3e1e6e9efeae1f6e1aeedefe4e5ecaecdeff6e9e529dd9b08b9cfb44e828083ca8082e9e4c98086f0efe9eef4f3cc8084eee1ede5f48092cceae1f6e1afece1eee7afd3f4f2e9eee7bbf8f08080808080808083808080d8f48087d2e5f6e5eee7e5' to parameter: 2; Wrong data type: java.lang.NumberFormatException: For input string: "[B@c89f0"
2014-02-13T23:35:34.410-0200|WARNING: SQL Error: -16, SQLState: 37000
2014-02-13T23:35:34.413-0200|SEVERE: Wrong data type: java.lang.NumberFormatException: For input string: "[B@c89f0"
2014-02-13T23:35:34.416-0200|INFO: Error performing load command
org.hibernate.exception.SQLGrammarException: could not load an entity: [br.com.desafiojava.model.VoteUser#component[chaveUser,movieId]{movieId=2c6d8085f3f2809ee2f2aee3efedaee4e5f3e1e6e9efeae1f6e1aeedefe4e5ecaecdeff6e9e529dd9b08b9cfb44e828083ca8082e9e4c98086f0efe9eef4f3cc8084eee1ede5f48092cceae1f6e1afece1eee7afd3f4f2e9eee7bbf8f08080808080808083808080d8f48087d2e5f6e5eee7e5, chaveUser=454c8d6b-2ea6-4d26-9df7-b44eba065f2e}]
org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164)
    at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
Caused by: java.sql.SQLException: Wrong data type: java.lang.NumberFormatException: For input string: "[B@c89f0"
    at org.hsqldb.jdbc.Util.throwError(Unknown Source)

2014-02-13T23:35:34.441-0200|INFO: 2014-02-13 23:35:34,431 DEBUG org.apache.struts2.dispatcher.Dispatcher. debug: 80 - Exception occurred during processing Caused by: java.sql.SQLException: Wrong data type: java.lang.NumberFormatException: For input string: "[B@c89f0"
    at org.hsqldb.jdbc.Util.throwError(Unknown Source)
    at org.hsqldb.jdbc.jdbcPreparedStatement.setParameter(Unknown Source)
    at org.hsqldb.jdbc.jdbcPreparedStatement.setBytes(Unknown Source)
    at org.hibernate.type.AbstractBynaryType.set(AbstractBynaryType.java:66)
    at org.hibernate.type.SerializableType.set(SerializableType.java:52)
    at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:154)
    at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:136)
    at org.hibernate.type.ComponentType.nullSafeSet(ComponentType.java:312)
    at org.hibernate.loader.Loader.bindPositionalParameters(Loader.java:1769)
    at org.hibernate.loader.Loader.bindParameterValues(Loader.java:1740)
    at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1612)
    at org.hibernate.loader.Loader.doQuery(Loader.java:717)
    at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:270)
    at org.hibernate.loader.Loader.loadEntity(Loader.java:1933)
    ... 100 more

minhas classes:

package br.com.desafiojava.model.pk;

import java.io.Serializable;

import javax.persistence.Embeddable;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;

import br.com.desafiojava.model.Movie;

@Embeddable
public class VoteUserId implements Serializable {

   private static final long serialVersionUID = 1684508547840147866L;

   private String chaveUser;

   private Movie movieId;

   public VoteUserId() {}

   public VoteUserId(String chaveUser, Movie movieId) {
       this.chaveUser = chaveUser;
       this.movieId = movieId;
   }

    public final String getChaveUser() {
        return chaveUser;
    }

    public final void setChaveUser(String chaveUser) {
        this.chaveUser = chaveUser;
    }

    @ManyToOne(fetch=FetchType.EAGER, targetEntity = Movie.class)
    @JoinColumn(name="movieid", unique=false, nullable=true, insertable=true, updatable=true)
    public final Movie getMovieId() {
        return movieId;
    }

    public final void setMovieId(Movie movieId) {
        this.movieId = movieId;
    }   
}
package br.com.desafiojava.model;

import java.io.Serializable;

import javax.persistence.EmbeddedId;
import javax.persistence.Entity;

import br.com.desafiojava.model.pk.VoteUserId;

@Entity
public class VoteUser implements Serializable {

    private static final long serialVersionUID = -8957440229738353544L;

    @EmbeddedId
    private VoteUserId voteUserId;    

    private int points;

    public final VoteUserId getVoteUserId() {
        return voteUserId;
    }

    public final void setVoteUserId(VoteUserId voteUserId) {
        this.voteUserId = voteUserId;
    }

    public final int getPoints() {
        return points;
    }

    public final void setPoints(int points) {
        this.points = points;
    }    
}

E o método de persistencia:

public void voteMovie(long id, String uuid){

        Movie movie = this.find(id);
        VoteUserId voteUserId = new VoteUserId(uuid,movie);
        VoteUser voteUser = this.find(voteUserId);

        if(voteUser == null)
        {
            voteUser = new VoteUser();
        }

        movie.setPoints(movie.getPoints()+1);
        voteUser.setPoints(voteUser.getPoints()+1);
        this.entityManager.persist(movie);
        this.entityManager.persist(voteUser);
    }
  1. Você vai ver essas setas em qualquer página de pergunta. Com elas, você pode dizer se uma pergunta ou uma resposta foram relevantes ou não.
  2. Edite sua pergunta ou resposta caso queira alterar ou adicionar detalhes.
  3. Caso haja alguma dúvida sobre a pergunta, adicione um comentário. O espaço de respostas deve ser utilizado apenas para responder a pergunta.
  4. Se o autor da pergunta marcar uma resposta como solucionada, esta marca aparecerá.
  5. Clique aqui para mais detalhes sobre o funcionamento do GUJ!

1 resposta

Não é a resposta que estava procurando? Procure outras perguntas com as tags hibernate jpa struts ou faça a sua própria pergunta.