Erro no save do hibernate

3 respostas
alberto_ribeiro

Boa tarde pessoal, estou desenvolvendo uma parte de um sistema que usa hibernate annotations e estou recebendo um erro estranho na hora do save, alguém poderia me ajudar ? por favor…

Classe

@Entity
@Table(name = "senhaextrato")
public class SenhaExtrato implements Serializable {

	private static final long serialVersionUID = 1L;

	@Id
	@Column
	private Integer recurso;

	@Column(name = "recursoabet")
	private Integer recursoAbet;

	@Column(name = "cnpj_cpf")
	private String cnpjCpf;

	@Column
	private String senha;

	@Column
	@Temporal(TemporalType.TIMESTAMP)
	private Date dtInclusao;

	@Column
	@Temporal(TemporalType.TIMESTAMP)
	private Date dtAlteracao;

	@Column
	@Temporal(TemporalType.TIMESTAMP)
	private Date dtdownload;

	@Column
	private String email;

Tabela

CREATE TABLE senhaextrato
(
  recurso int4 NOT NULL,
  senha varchar(10) NOT NULL,
  dtinclusao timestamptz,
  dtalteracao timestamptz,
  email varchar(46),
  recursoabet int4,
  cnpj_cpf varchar(14),
  dtdownload timestamptz,
  CONSTRAINT pksenhaextrato PRIMARY KEY (recurso)
)

Teste

public void testCriaLoginRecurso2() {
		SenhaExtrato senhaExtrato = new SenhaExtrato();
		senhaExtrato.setRecursoAbet(1);
		senhaExtrato.setCnpjCpf("bx");
		senhaExtrato.setSenha("250200");
		senhaExtrato.setDtInclusao(new Date());
		senhaExtrato.setDtAlteracao(new Date());
		senhaExtrato.setDtdownload(new Date());
		senhaExtrato.setEmail("rsdfd");
		senhaExtrato.setRecurso(251200);

		Session session = HibernateUtil.getCurrentSession();
		Transaction tx = session.beginTransaction();

		session.save(senhaExtrato);
		tx.commit();
		session.close();

	}

Erro

Hibernate: insert into senhaextrato (recursoabet, cnpj_cpf, senha, dtInclusao, dtAlteracao, dtdownload, email, recurso) values (?, ?, ?, ?, ?, ?, ?, ?)
com.mchange.v2.c3p0.impl.NewPooledConnection@1484a05 invalidated by Exception: java.lang.ArrayIndexOutOfBoundsException: 1
	at org.postgresql.core.QueryExecutor.sendQuery(QueryExecutor.java:143)
	at org.postgresql.core.QueryExecutor.execute(QueryExecutor.java:65)
	at org.postgresql.jdbc1.AbstractJdbc1Connection.ExecSQL(AbstractJdbc1Connection.java:451)
	at org.postgresql.jdbc1.AbstractJdbc1Statement.execute(AbstractJdbc1Statement.java:281)
	at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:48)
	at org.postgresql.jdbc1.AbstractJdbc1Statement.executeUpdate(AbstractJdbc1Statement.java:179)
	at org.postgresql.jdbc1.AbstractJdbc1Statement.executeUpdate(AbstractJdbc1Statement.java:165)
	at org.postgresql.jdbc2.AbstractJdbc2Statement.executeBatch(AbstractJdbc2Statement.java:80)
	at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeBatch(NewProxyPreparedStatement.java:1722)
	at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)
	at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:242)
	at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:235)
	at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:139)
	at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
	at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
	at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
	at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
	at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
	at br.com.abet.componentLogin.application.common.validalogin.impl.ValidaLoginImplTeste.testCriaLoginRecurso2(ValidaLoginImplTeste.java:277)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at junit.framework.TestCase.runTest(TestCase.java:154)
	at junit.framework.TestCase.runBare(TestCase.java:127)
	at junit.framework.TestResult$1.protect(TestResult.java:106)
	at junit.framework.TestResult.runProtected(TestResult.java:124)
	at junit.framework.TestResult.run(TestResult.java:109)
	at junit.framework.TestCase.run(TestCase.java:118)
	at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:128)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
CONNECTION ERROR OCCURRED!

[]'s e obrigado…

3 Respostas

Marky.Vasconcelos

tenta da um session.flush() antes do close();

jamikas

pela mensagem, a sua conexão não esta rolando! Debug e olha se antes do save a session esta como null.

abços.

alberto_ribeiro

Obrigado a todos… resolvido

o problema era versão de driver do postgres…

[]'s

Criado 4 de junho de 2007
Ultima resposta 5 de jun. de 2007
Respostas 3
Participantes 3