From: | Miroslav Nachev <miro(at)space-comm(dot)com> |
---|---|
To: | Kris Jurka <books(at)ejurka(dot)com> |
Cc: | pgsql-bugs(at)postgresql(dot)org |
Subject: | Re: BUG #4586: Supporting of Binary instead Bytea for Primary Keys |
Date: | 2008-12-17 23:07:30 |
Message-ID: | 49498632.80305@space-comm.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-bugs |
Hi,
What if I convert to/from byte array with (see the attached java number
utility class):
NumberUtils.toByteArray(UUID uuid)
NumberUtils.toUUID(byte[] value)
Miro.
Miroslav Nachev wrote:
> Yes, you are right. With the correct code:
> public static void main(String[] args) {
> UUID uuid = UUID.randomUUID();
> TestTable1 testTable = new TestTable1(uuid);
> persist(testTable);
> }
>
> the exception is:
> Hibernate: insert into test_db.public.test_table_1 (description,
> my_id) values (?, ?)
> 2008-12-18 0:58:39 org.hibernate.util.JDBCExceptionReporter logExceptions
> WARNING: SQL Error: 0, SQLState: null
> 2008-12-18 0:58:39 org.hibernate.util.JDBCExceptionReporter logExceptions
> SEVERE: Batch entry 0 insert into test_db.public.test_table_1
> (description, my_id) values (NULL, '<stream of 80 bytes>') was
> aborted. Call getNextException to see the cause.
> 2008-12-18 0:58:39 org.hibernate.util.JDBCExceptionReporter logExceptions
> WARNING: SQL Error: 0, SQLState: 42804
> 2008-12-18 0:58:39 org.hibernate.util.JDBCExceptionReporter logExceptions
> SEVERE: ERROR: column "my_id" is of type uuid but expression is of
> type bytea
> Hint: You will need to rewrite or cast the expression.
> Position: 55
> 2008-12-18 0:58:39
> org.hibernate.event.def.AbstractFlushingEventListener performExecutions
> SEVERE: Could not synchronize database state with session
> org.hibernate.exception.SQLGrammarException: Could not execute JDBC
> batch update
> at
> org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
>
> at
> org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
>
> at
> org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:253)
> at
> org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:237)
> at
> org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:141)
> at
> org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
>
> at
> org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
>
> at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
> at
> org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
> at
> org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
>
> at
> org.hibernate.ejb.TransactionImpl.commit(TransactionImpl.java:54)
> at psqluuidtest.Main.persist(Main.java:34)
> at psqluuidtest.Main.main(Main.java:25)
> Caused by: java.sql.BatchUpdateException: Batch entry 0 insert into
> test_db.public.test_table_1 (description, my_id) values (NULL,
> '<stream of 80 bytes>') was aborted. Call getNextException to see the
> cause.
> at
> org.postgresql.jdbc2.AbstractJdbc2Statement$BatchResultHandler.handleError(AbstractJdbc2Statement.java:2556)
>
> at
> org.postgresql.core.v3.QueryExecutorImpl$1.handleError(QueryExecutorImpl.java:395)
>
> at
> org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1348)
>
> at
> org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:343)
>
> at
> org.postgresql.jdbc2.AbstractJdbc2Statement.executeBatch(AbstractJdbc2Statement.java:2693)
>
> at
> org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)
>
> at
> org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:246)
> ... 10 more
> javax.persistence.RollbackException: Error while commiting the
> transaction
> at
> org.hibernate.ejb.TransactionImpl.commit(TransactionImpl.java:71)
> at psqluuidtest.Main.persist(Main.java:34)
> at psqluuidtest.Main.main(Main.java:25)
> Caused by: org.hibernate.exception.SQLGrammarException: Could not
> execute JDBC batch update
> at
> org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
>
> at
> org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
>
> at
> org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:253)
> at
> org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:237)
> at
> org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:141)
> at
> org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
>
> at
> org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
>
> at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
> at
> org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
> at
> org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
>
> at
> org.hibernate.ejb.TransactionImpl.commit(TransactionImpl.java:54)
> ... 2 more
> Caused by: java.sql.BatchUpdateException: Batch entry 0 insert into
> test_db.public.test_table_1 (description, my_id) values (NULL,
> '<stream of 80 bytes>') was aborted. Call getNextException to see the
> cause.
> at
> org.postgresql.jdbc2.AbstractJdbc2Statement$BatchResultHandler.handleError(AbstractJdbc2Statement.java:2556)
>
> at
> org.postgresql.core.v3.QueryExecutorImpl$1.handleError(QueryExecutorImpl.java:395)
>
> at
> org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1348)
>
> at
> org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:343)
>
> at
> org.postgresql.jdbc2.AbstractJdbc2Statement.executeBatch(AbstractJdbc2Statement.java:2693)
>
> at
> org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)
>
> at
> org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:246)
> ... 10 more
> Exception in thread "main" java.lang.IllegalStateException:
> Transaction not active
> at
> org.hibernate.ejb.TransactionImpl.rollback(TransactionImpl.java:82)
> at psqluuidtest.Main.persist(Main.java:37)
> at psqluuidtest.Main.main(Main.java:25)
>
>
>
> Miro.
>
>
> Kris Jurka wrote:
>> Miroslav Nachev wrote:
>>> I try to use it but I have the following exception:
>>>
>>> java.lang.IllegalArgumentException: Unknown entity: java.util.UUID
>>> at
>>> org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:223)
>>>
>>> at psqluuidtest.Main.persist(Main.java:33)
>>> at psqluuidtest.Main.main(Main..java:25)
>>>
>>
>> Surely you want to persist a TestTable1 instance, not the uuid itself.
>>
>> Kris Jurka
>>
>
>
Attachment | Content-Type | Size |
---|---|---|
NumberUtils.java | text/plain | 5.2 KB |
From | Date | Subject | |
---|---|---|---|
Next Message | Богданов В. | 2008-12-18 07:51:05 | Page header error on PGSQL 7.4.5 |
Previous Message | Miroslav Nachev | 2008-12-17 23:00:54 | Re: BUG #4586: Supporting of Binary instead Bytea for Primary Keys |