开发者

Update Table with Hibernate Problem

I'm not able to update a table with Hibernate. The table is created with the following statement and stored in a PostgreSQL Database.

CREATE TABLE staat
(
  sta_id serial NOT NULL, -- ID des Staates
  sta_bezeichnung character varying(50) NOT NULL, -- Langbezeichnung
  sta_lkz character varying(10) NOT NULL, -- Laenderkennzeichen
  sta_vorwahl character varying(10), -- Telefon Landesvorwahl
  sta_eu boolean DEFAULT false, -- Ist der Staaat ein EU-Mitglied?
  CONSTRAINT staat_pkey PRIMARY KEY (sta_id),
  CONSTRAINT staat_sta_bezeichnung_key UNIQUE (sta_bezeichnung)
)
WITH (
  OIDS=FALSE
);

Rights are set correct, because select, insert and update are possible with a SQL Manager. The following update statement also works with the SQL Manager.

But now the problem: when I want to update the table with my application, it generates PSQLException with the following output: WARNUNG: SQL Error: 0, SQLState: 22004 and ERROR: query string argument of EXECUTE is null

The source code:

Query q = s.createQuery("Update Staat set sta_bezeichnung = 'BlaBla' where sta_id = 1");
int status = q.executeUpdate();

I think the problem has something to do with NOT NULL columns, because tables without NOT NULL columns can be updated with the same source code...

Does anyone has an idea of what is wrong or what I have to do???

Edit: tried with SQL (q.executeSQLUpdate) and HQL

Transaction tr = s.beginTransaction();
staat = (Staat)s.get(Staat.class, new Integer(0));
staat.setStaBezeichnung("BlaBla");
s.update(staat);
tr.commit();

Generates followin error: ERROR: query string argu开发者_开发问答ment of EXECUTE is null and Could not synchronize database state with session

Edit2: update works fine without hibernate


Please check your Hibernate mapping file for Staat maybe you have not configured a not-null constraint for some attribute/field, which is not-null in database.


It looks like you are trying to use SQL query where HQL query is expected. Try

Query q = s.createSQLQuery(....);

Or better yet, use mapped classes with HQL. But I don't know your mapped classes, so can't speculate on specifics.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜