Hibernate + postgresql

1 resposta
A

Olá Amigos:

Estou com o seguinte problema.

Ao tentar inserir um registro no postgresql utilizando hibernate aparece a seguinte excessão:

Erro: Could not execute JDBC batch update

A sql que ele gera é insert into MARCA (NM_DESCRICAO, DT_CADASTRO, CD_MARCA) values (teste, null, 54)

tentei executar a query direto no postgre e não funcionou, observei que ela só funciona assim:

insert into “MARCA” (“NM_DESCRICAO”, “DT_CADASTRO”, “CD_MARCA”) values (‘teste’, null, 34)

DDL da tabela:

CREATE TABLE "public"."MARCA" (

"CD_MARCA" SERIAL,

"NM_DESCRICAO" VARCHAR(50),

"DT_CADASTRO" DATE,

CONSTRAINT "MARCA_pkey" PRIMARY KEY("CD_MARCA")

) WITH OIDS;
marca.hbm.xml

<?xml version=‘1.0’ encoding=‘utf-8’?>

<!DOCTYPE hibernate-mapping PUBLIC “-//Hibernate/Hibernate Mapping DTD 3.0//EN” “<a href="http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd</a>”>

<hibernate-mapping>

<class name=“br.teste.beans.Marca” table=“MARCA”>

<id column=“CD_MARCA” name=“cdMarca” type=“java.lang.Integer”>

<generator class=“sequence”>

<param name=“sequence”>seq_fabricante</param>

</generator>
</id>

<property column=“NM_DESCRICAO” length=“50” name=“nmDescricao” not-null=“true” type=“java.lang.String” />

<property column=“DT_CADASTRO” name=“dtCadastro” type=“java.util.Date”/>

</class>

</hibernate-mapping>

hibernate.cfg.xml

<?xml version=‘1.0’ encoding=‘utf-8’?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd”>
<hibernate-configuration>
<session-factory>
<property name=“hibernate.dialect”>org.hibernate.dialect.PostgreSQLDialect</property>
<property name=“hibernate.connection.driver_class”>org.postgresql.Driver</property>
<property name=“hibernate.connection.url”>jdbc:postgresql://localhost:5432/APVarejo</property>
<property name=“hibernate.connection.username”>postgres</property>
<property name=“hibernate.connection.password”>postgres</property>
<property name=“hibernate.show_sql”>true</property>
<mapping resource=“marca.hbm.xml”/>
</session-factory>

</hibernate-configuration>

Alguem pode me ajudar?

1 Resposta

D

“estranho”, vê no teu postgre como está os nomes da tabela e das colunas se está com as " (aspas), pode ser esse o problema, se estiverem tu tem q mapear a tabela e a coluna corretamente para ter as aspas também, mas eu aconselharia tirá-las do esquema ddl para não ter aspas.

Criado 20 de fevereiro de 2008
Ultima resposta 21 de fev. de 2008
Respostas 1
Participantes 2