Skip to content

GeneratedKeyHolder.getKey returns NULL with postgres [SPR-7564] #12221

@spring-projects-issues

Description

@spring-projects-issues

Adrian opened SPR-7564 and commented

On the forum there is thread that this problem cannot be solved (http://forum.springsource.org/showthread.php?t=19293).

The latest JDBC drives for postgres seam to work fine when returning the generated keys from a prepared statement but Spring Framework still seams to have issues getting this key. When calling getKey on a GeneratedKeyHolder object NULL is returned, whereas the following plain jdbc code works fine:

PreparedStatement preparedStatement = connection.prepareStatement(SQL,
		PreparedStatement.RETURN_GENERATED_KEYS);
preparedStatement.setString(1, entityType.getMetaData());

preparedStatement.executeUpdate();

Long entityPrimaryKey = null;

ResultSet generatedKeys = preparedStatement.getGeneratedKeys();
if (generatedKeys.next()) 
	entityPrimaryKey = Long.valueOf(generatedKeys.getLong(1));

preparedStatement.close();

My table definition on postgres is as follows:

CREATE  TABLE  "entity_type" (
  "entity_type_id" SERIAL ,
  "meta_data" TEXT NOT NULL ,
  PRIMARY KEY ("entity_type_id") );

Affects: 3.0.4

Reference URL: http://forum.springsource.org/showthread.php?t=19293

Attachments:

Referenced from: commits 97e047e

Metadata

Metadata

Assignees

No one assigned

    Labels

    in: dataIssues in data modules (jdbc, orm, oxm, tx)type: enhancementA general enhancement

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions