Re: Problems with Hibernate Discriminators and 9.0-801.jdbc4 - Mailing list pgsql-jdbc

From sdavidr
Subject Re: Problems with Hibernate Discriminators and 9.0-801.jdbc4
Date
Msg-id 1301317540172-4267556.post@n5.nabble.com
Whole thread Raw
In response to Re: Problems with Hibernate Discriminators and 9.0-801.jdbc4  (Dave Cramer <pg@fastcrypt.com>)
Responses Re: Problems with Hibernate Discriminators and 9.0-801.jdbc4
Re: Problems with Hibernate Discriminators and 9.0-801.jdbc4
List pgsql-jdbc
Ok, that's the hibernate's code that is failing. As it says :Extract the
value from the result set (which is assumed to already have been positioned
to the apopriate row).

Hibernate could receive a lot of numbers from a "returning *" but doesn't
know what is the correct value. It expects to be the first element, but if
is not, it fails.  Normally, the id is the first returned element by
postgres, but in some tables that is not true -> when there is a string
discriminator in the first column.

In another way, method from postgres driver getGeneratedKeys cannot return
the full table, isn't it?


/**
     * Extract the value from the result set (which is assumed to already have
been positioned to the apopriate row)
     * and wrp it in the appropriate Java numeric type.
     *
     * @param rs The result set from which to extract the value.
     * @param type The expected type of the value.
     * @return The extracted value.
     * @throws SQLException Indicates problems access the result set
     * @throws IdentifierGenerationException Indicates an unknown type.
     */
    public static Serializable get(ResultSet rs, Type type) throws
SQLException, IdentifierGenerationException {
        if ( ResultSetIdentifierConsumer.class.isInstance( type ) ) {
            return ( ( ResultSetIdentifierConsumer ) type ).consumeIdentifier( rs );
        }
        if ( CustomType.class.isInstance( type ) ) {
            final CustomType customType = (CustomType) type;
            if ( ResultSetIdentifierConsumer.class.isInstance(
customType.getUserType() ) ) {
                return ( (ResultSetIdentifierConsumer) customType.getUserType()
).consumeIdentifier( rs );
            }
        }

        Class clazz = type.getReturnedClass();
        if ( clazz == Long.class ) {
            return new Long( rs.getLong( 1 ) );
        }
        else if ( clazz == Integer.class ) {
            return new Integer( rs.getInt( 1 ) );
        }
        else if ( clazz == Short.class ) {
            return new Short( rs.getShort( 1 ) );
        }
        else if ( clazz == String.class ) {
            return rs.getString( 1 );
        }
        else if ( clazz == BigInteger.class ) {
            return rs.getBigDecimal( 1 ).setScale( 0, BigDecimal.ROUND_UNNECESSARY
).toBigInteger();
        }
        else if ( clazz == BigDecimal.class ) {
            return rs.getBigDecimal( 1 ).setScale( 0, BigDecimal.ROUND_UNNECESSARY );
        }
        else {
            throw new IdentifierGenerationException(
                    "unrecognized id type : " + type.getName() + " -> " + clazz.getName()
            );
        }
    }

--
View this message in context:
http://postgresql.1045698.n5.nabble.com/Problems-with-Hibernate-Discriminators-and-9-0-801-jdbc4-tp4259788p4267556.html
Sent from the PostgreSQL - jdbc mailing list archive at Nabble.com.

pgsql-jdbc by date:

Previous
From: "MauMau"
Date:
Subject: Re: JDBC gripe list
Next
From: Dave Cramer
Date:
Subject: Re: Problems with Hibernate Discriminators and 9.0-801.jdbc4