Porblemas em mapear um InputStream para JPA no postgres

0 respostas
ronnypeterson

Estou precisando inserir um atributo do tipo InputStream em um campo bytea no postgres. Porém não sei qual mapeamento devo usar no JPA. Qquando tento inserir aparece o seguinte erro:

[TopLink Warning]: 2008.03.31 08:36:25.218--UnitOfWork(7572744)--Exception [TOPLINK-4002] (Oracle TopLink Essentials - 2006.8 (Build 060830)): oracle.toplink.essentials.exceptions.DatabaseException
Internal Exception: org.postgresql.util.PSQLException: Não pode inferir um tipo SQL a ser usado para uma instância de java.io.ByteArrayInputStream. Use setObject() com um valor de Types explícito para especificar o tipo a ser usado.Error Code: 0
Call:INSERT INTO usuarios (DIGITAL1, DIGITAL2, TX_SENHA, USUARIO_ID, TX_LOGIN, CREATED_ON, CS_SITUACAO, UPDATED_ON, TX_NOME, grupo_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
	bind => [java.io.ByteArrayInputStream@5f2db0, java.io.ByteArrayInputStream@b0a3f5, 123456, 3, cmagno, 2008-03-31 08:36:25.203, 1, 2008-03-31 08:36:25.203, JORGE CARLOS MAGNO, 1]
Query:InsertObjectQuery(model.Usuario@df0438)

A minha classe é:

package model;

import java.io.InputStream;
import java.sql.Timestamp;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

@Entity
@Table(name="usuarios") 
@NamedQueries(value={
		//@NamedQuery(name="usuarioByTodos", query="select u from Usuario u where u.sit_exclusao = 1"),
		@NamedQuery(name="usuarioByLogin", query="select u from Usuario u where u.tx_login like :login and u.cs_situacao = 1 order by u.tx_nome"),
		@NamedQuery(name="verificaLogin", query="select u from Usuario u where u.tx_login = :login order by u.tx_nome"),
		//@NamedQuery(name="verificaSenha", query="select u from Usuario u where u.id = :id and u.sit_exclusao = 1 order by u.nome"),
	    @NamedQuery(name="usuarioByNome", query="select u from Usuario u where upper(u.tx_nome) like :nome and u.cs_situacao = 1 order by u.tx_nome")
})
public class Usuario 
{
	@Id
	@Column (insertable = false)
	@GeneratedValue (strategy = GenerationType.SEQUENCE, generator = "usuario_id_seq")
	private int id;
	
	@ManyToOne //(cascade=CascadeType.MERGE)
	@JoinColumn(name="grupo_id") 
	private Grupo grupo_id;
	
	private String tx_nome;
	  
	private String tx_senha;
	  
	private int cs_situacao;
	 
	private String tx_login;
		
	private InputStream digital1 = null;
	  
	private InputStream digital2 = null;
	  
	private int usuario_id;
	
	//@Temporal(TemporalType.DATE)  
	private Timestamp created_on;
	
	//@Temporal(TemporalType.DATE)   
	private Timestamp updated_on;
	
	/**
	 * @return the created_on
	 */
	public Timestamp getCreated_on() {
		return created_on;
	}
	
	/**
	 * @param created_on the created_on to set
	 */
	public void setCreated_on(Timestamp created_on) {
		this.created_on = created_on;
	}
	
	/**
	 * @return the cs_situacao
	 */
	public int getCs_situacao() {
		return cs_situacao;
	}
	
	/**
	 * @param cs_situacao the cs_situacao to set
	 */
	public void setCs_situacao(int cs_situacao) {
		this.cs_situacao = cs_situacao;
	}
	
	/**
	 * @return the digital1
	 */
	public InputStream getDigital1() {
		return digital1;
	}
	
	/**
	 * @param digital1 the digital1 to set
	 */
	public void setDigital1(InputStream digital1) {
		this.digital1 = digital1;
	}
	
	/**
	 * @return the digital2
	 */
	public InputStream getDigital2() {
		return digital2;
	}
	
	/**
	 * @param digital2 the digital2 to set
	 */
	public void setDigital2(InputStream digital2) {
		this.digital2 = digital2;
	}
	
	/**
	 * @return the grupo_id
	 */
	public Grupo getGrupo_id() {
		return grupo_id;
	}
	
	/**
	 * @param grupo_id the grupo_id to set
	 */
	public void setGrupo_id(Grupo grupo_id) {
		this.grupo_id = grupo_id;
	}
	
	/**
	 * @return the id
	 */
	public int getId() {
		return id;
	}
	
	/**
	 * @param id the id to set
	 */
	public void setId(int id) {
		this.id = id;
	}
	
	/**
	 * @return the tx_login
	 */
	public String getTx_login() {
		return tx_login;
	}
	
	/**
	 * @param tx_login the tx_login to set
	 */
	public void setTx_login(String tx_login) {
		this.tx_login = tx_login;
	}
	
	/**
	 * @return the tx_nome
	 */
	public String getTx_nome() {
		return tx_nome;
	}
	
	/**
	 * @param tx_nome the tx_nome to set
	 */
	public void setTx_nome(String tx_nome) {
		this.tx_nome = tx_nome;
	}
	
	/**
	 * @return the tx_senha
	 */
	public String getTx_senha() {
		return tx_senha;
	}
	
	/**
	 * @param tx_senha the tx_senha to set
	 */
	public void setTx_senha(String tx_senha) {
		this.tx_senha = tx_senha;
	}
	
	/**
	 * @return the updated_on
	 */
	public Timestamp getUpdated_on() {
		return updated_on;
	}
	
	/**
	 * @param updated_on the updated_on to set
	 */
	public void setUpdated_on(Timestamp updated_on) {
		this.updated_on = updated_on;
	}
	
	/**
	 * @return the usuario_id
	 */
	public int getUsuario_id() {
		return usuario_id;
	}
	
	/**
	 * @param usuario_id the usuario_id to set
	 */
	public void setUsuario_id(int usuario_id) {
		this.usuario_id = usuario_id;
	}
}

Desde já agradeço a atenção e colaboração de todos.

Criado 31 de março de 2008
Respostas 0
Participantes 1