Re: Problems with Hibernate Discriminators and 9.0-801.jdbc4

Поиск
Список
Период
Сортировка
От sdavidr
Тема Re: Problems with Hibernate Discriminators and 9.0-801.jdbc4
Дата
Msg-id 1301317540172-4267556.post@n5.nabble.com
обсуждение исходный текст
Ответ на Re: Problems with Hibernate Discriminators and 9.0-801.jdbc4  (Dave Cramer <pg@fastcrypt.com>)
Ответы Re: Problems with Hibernate Discriminators and 9.0-801.jdbc4  (Dave Cramer <pg@fastcrypt.com>)
Re: Problems with Hibernate Discriminators and 9.0-801.jdbc4  (Oliver Jowett <oliver@opencloud.com>)
Список 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 по дате отправления:

Предыдущее
От: "MauMau"
Дата:
Сообщение: Re: JDBC gripe list
Следующее
От: Dave Cramer
Дата:
Сообщение: Re: Problems with Hibernate Discriminators and 9.0-801.jdbc4