i have a problem where everything seems to be ok, no exceptions are thrown but data is not written in database.
i've used Session.load() to verify that i can normally access data already in database (so configuration should be ok) and SQLQuery to avoid problems with mapping.
also, i've tried replacing postgres with mysql and everything worked as expected in mysql. is there some additional configuration required for this to work in postgres?
Aljosa
hibernate.cfg.xml:
Code:
<?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/pgtest</property>
<property name="hibernate.connection.username">pgtest</property>
<property name="hibernate.connection.password">pgtest</property>
<property name="hibernate.show_sql">true</property>
<mapping resource="pgtest/Pgtest.hbm.xml"/>
</session-factory>
</hibernate-configuration>
Postgres:Code:
postgres=# create database pgtest;
CREATE DATABASE
postgres=# \c pgtest
You are now connected to database "pgtest".
pgtest=# CREATE SEQUENCE pgtest_seq;
CREATE SEQUENCE
pgtest=# CREATE TABLE pgtest(id integer not null primary key default nextval('pgtest_seq'), test varchar(50));
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "pgtest_pkey" for table "pgtest"
CREATE TABLE
pgtest=# insert into pgtest(test) values('test #1');
INSERT 0 1
pgtest=# SELECT * from pgtest;
id | test
----+---------
1 | test #1
(1 row)
pgtest=# CREATE USER pgtest with password 'pgtest';
CREATE ROLE
pgtest=# grant all privileges on pgtest to pgtest with grant option;
GRANT
pgtest=# grant all privileges on pgtest_seq to pgtest with grant option;
GRANT
Hibernate version: Hibernate-Version: 3.2.5.g
Mapping documents:Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 2009.02.19 15:23:31 by Hibernate Tools 3.2.1.GA -->
<hibernate-mapping>
<class name="pgtest.Pgtest" table="pgtest" schema="public">
<id name="id" type="int">
<column name="id" />
<generator class="assigned" />
</id>
<property name="test" type="string">
<column name="test" length="50" />
</property>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():Code:
Pgtest t = (Pgtest) session.load(Pgtest.class, 1);
System.out.println("pgtest(#1).test: " + t.getTest());
SQLQuery sql = session.createSQLQuery("insert into pgtest(test) values(?)");
sql.setString(0, "test #2");
System.out.println("sql: " + sql.getQueryString().toString());
System.out.println("result: " + sql.executeUpdate());
session.flush();
Run output:Code:
Hibernate: select pgtest0_.id as id0_0_, pgtest0_.test as test0_0_ from public.pgtest pgtest0_ where pgtest0_.id=?
pgtest(#1).test: test #1
sql: insert into pgtest(test) values(?)
Hibernate: insert into pgtest(test) values(?)
result: 1
Full stack trace of any exception that occurs:no exception occured
Name and version of the database you are using:postgresql 8.3.5-0ubuntu0.8.04
The generated SQL (show_sql=true):Code:
Hibernate: select pgtest0_.id as id0_0_, pgtest0_.test as test0_0_ from public.pgtest pgtest0_ where pgtest0_.id=?
Hibernate: insert into pgtest(test) values(?)