Hibernate: byte[] speichern

  • Themenstarter Themenstarter Verus
  • Beginndatum Beginndatum
Status
Nicht offen für weitere Antworten.
V

Verus

Gast
Moin,

ich versuche mich gerade daran ein byte[] in der Datenbank (Postgres) zu speichern.

Wenn ich einen Member habe der folgendermaßen aussieht:
Code:
@Lob
private byte[] bArray;

Wenn ich das ganze jetzt versuche zu speichern dann erhalte ich folgende Fehlermeldung:
ERROR: column "bArray" is of type bytea but expression is of type bigint

Lasse ich @Lob weg, dann funktioniert es. Aber sollte nicht Lob angeben werden, um zu zeigen, dass es sich um ein Blob handelt?

Wofür brauche ich denn nun Lob?
 
Sollte so funktionieren. Ich meine mit Lob-Annotation. Wie ist das Feld in der Datenbank definiert?
Was für Dialect ist in persistence.xml eingestellt? Wie sieht das SQL Statement aus, bei dem es scheitert?

Aktiviere dazu die Ausgabe von SQL in persistence.xml
Code:
<property name="hibernate.show_sql" value="true" />
 
Das Feld ist als bytea definiert. Ich habe als Dialekt org.hibernate.dialect.PostgreSQLDialect gewählt.

column "protocol" == bArray
Hier die komplette Fehlermeldung, die ich erhalte:

Hibernate: insert into protocol (creation_date, name, protocol, protocol_type, userref, id) values (?, ?, ?, ?, ?, ?)
0 [main] WARN org.hibernate.util.JDBCExceptionReporter - SQL Error: 0, SQLState: null
0 [main] ERROR org.hibernate.util.JDBCExceptionReporter - Batch-Eintrag 0 insert into protocol (creation_date, name, protocol, protocol_type, userref, id) values (2008-05-06 09:01:31.852000 +02:00:00, test1, 36037, NORMAL, 29, 30) wurde abgebrochen. Rufen Sie 'getNextException' auf, um die Ursache zu erfahren.
0 [main] WARN org.hibernate.util.JDBCExceptionReporter - SQL Error: 0, SQLState: 42804
0 [main] ERROR org.hibernate.util.JDBCExceptionReporter - ERROR: column "protocol" is of type bytea but expression is of type bigint
31 [main] ERROR org.hibernate.event.def.AbstractFlushingEventListener - 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:266)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:167)
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 Test.main(Test.java:229)
Caused by: java.sql.BatchUpdateException: Batch-Eintrag 0 insert into protocol (creation_date, name, protocol, protocol_type, userref, id) values (2008-05-06 09:01:31.852000 +02:00:00, test1, 36037, NORMAL, 29, 30) wurde abgebrochen. Rufen Sie 'getNextException' auf, um die Ursache zu erfahren.
at org.postgresql.jdbc2.AbstractJdbc2Statement$BatchResultHandler.handleError(AbstractJdbc2Statement.java:2534)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1317)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:350)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeBatch(AbstractJdbc2Statement.java:2596)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:246)
... 8 more
Exception in thread "main" 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:266)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:167)
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 Test.main(Test.java:229)
Caused by: java.sql.BatchUpdateException: Batch-Eintrag 0 insert into protocol (creation_date, name, protocol, protocol_type, userref, id) values (2008-05-06 09:01:31.852000 +02:00:00, test1, 36037, NORMAL, 29, 30) wurde abgebrochen. Rufen Sie 'getNextException' auf, um die Ursache zu erfahren.
at org.postgresql.jdbc2.AbstractJdbc2Statement$BatchResultHandler.handleError(AbstractJdbc2Statement.java:2534)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1317)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:350)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeBatch(AbstractJdbc2Statement.java:2596)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:246)
... 8 more
 
Der Typ in der Datenbank sollte bei Blobs in Postgres 'oid' sein, daher der Fehler.
Code:
CREATE TABLE WasAuchImmer (
   ...
   bArray oid,
   ...
);
 
Status
Nicht offen für weitere Antworten.

Zurück
Oben