pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: sdavidr <david.ricoma@gmail.com>
To: pgsql-jdbc@postgresql.org
Subject: Re: Problems with Hibernate Discriminators and 9.0-801.jdbc4
Date: Mon, 28 Mar 2011 06:05:40 -0700 (PDT)
Message-ID: <1301317540172-4267556.post@n5.nabble.com> (raw)
In-Reply-To: <AANLkTimHhNpk1Nx9kEza7DyffzTLH=P6ja4XM9j0-yCS@mail.gmail.com>
References: <1300923357612-4259788.post@n5.nabble.com>
	<AANLkTi=muHS+5uUaOoc-6EtNoMBWe39kotKxNTSXKqt-@mail.gmail.com>
	<1301299364557-4267176.post@n5.nabble.com>
	<AANLkTindSSqZiZwtPYKFfmBn+VWqCOrq8F+YC6JLb-eF@mail.gmail.com>
	<AANLkTimHhNpk1Nx9kEza7DyffzTLH=P6ja4XM9j0-yCS@mail.gmail.com>

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-tp4...
Sent from the PostgreSQL - jdbc mailing list archive at Nabble.com.



view thread (19+ messages)  latest in thread

Message-ID: <1301317540172-4267556.post@n5.nabble.com>
Permalink:  ../1301317540172-4267556.post@n5.nabble.com/
Also on:    postgresql.org/message-id/1301317540172-4267556.post@n5.nabble.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: david.ricoma@gmail.com
  Subject: Re: Problems with Hibernate Discriminators and 9.0-801.jdbc4
  In-Reply-To: <1301317540172-4267556.post@n5.nabble.com>
  References: <1300923357612-4259788.post@n5.nabble.com> <AANLkTi=muHS+5uUaOoc-6EtNoMBWe39kotKxNTSXKqt-@mail.gmail.com> <1301299364557-4267176.post@n5.nabble.com> <AANLkTindSSqZiZwtPYKFfmBn+VWqCOrq8F+YC6JLb-eF@mail.gmail.com> <AANLkTimHhNpk1Nx9kEza7DyffzTLH=P6ja4XM9j0-yCS@mail.gmail.com> <1301317540172-4267556.post@n5.nabble.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox