Upgrading from Jaybird 2.2 to 3.0

20 views
Skip to first unread message

Jim Campana

unread,
Jul 27, 2020, 4:00:38 PM7/27/20
to firebird-java
I am trying to upgrade Jaybird from 2.2.15 to 3.09, and have come across an error related to blobs.  
I have a few unit tests that generate a XML document (read from DB), and am getting a "blobId must be non-zero for an input blob" error (which I found an assertion was introduced in the 3.0 driver.) Has anyone run into this issue, and gotten around it?

Configuration for application:
  • HikariCP 2.4.4
  • hibernate-core 5.4.2.Final
  • javaVersion 1.8

Mark Rotteveel

unread,
Jul 27, 2020, 4:26:20 PM7/27/20
to firebi...@googlegroups.com
On 27-07-2020 21:42, Jim Campana wrote:
> I am trying to upgrade Jaybird from 2.2.15 to 3.09, and have come across
> an error related to blobs.
> I have a few unit tests that generate a XML document (read from DB), and
> am getting a "blobId must be non-zero for an input blob" error (which I
> found an assertion was introduced in the 3.0 driver.) Has anyone run
> into this issue, and gotten around it?
>
> Configuration for application:
>
> * HikariCP 2.4.4
> * hibernate-core 5.4.2.Final
> * javaVersion 1.8

Blobids cannot be zero, so this would mean that the code is accessing an
uninitialized field or something like that. Can you provide a
self-contained example to reproduce this?

Mark
--
Mark Rotteveel

Jim Campana

unread,
Jul 28, 2020, 8:28:44 AM7/28/20
to firebird-java
Example Code:

  @Test
  @Transactional
  public void findResults() {
    List<DiagTestResult> results = diagTestResultDao.getByOrderLink(129);
  }

DAO CLASS

@Repository("diagTestResultDao")
public class DiagTestResultDaoImpl extends AbstractPatientRecordDao<DiagTestResult> implements
    DiagTestResultDao {
    public static final String QUERY_GET_BY_ORDERLINK_HQL = "from DiagTestResult dtr where dtr.diagTestOrder.id = :orderLink";

    @Override
    public List<DiagTestResult> getByOrderLink(int orderLink) {
        Session session = sessionFactory.getCurrentSession();
        Query query = session.createQuery(QUERY_GET_BY_ORDERLINK_HQL).setParameter("orderLink", orderLink);
        if (query.list() != null) {
            return query.list();
        } else {
            return null;
        }
    }
}

public class DiagTestResult  {

  private int trnsxno;
  private Patient patient;
  private LocalDateTime date1;
  private DiagTestOrder diagTestOrder;
  private String notes;                  // Blob field
}

Arioch The

unread,
Jul 28, 2020, 8:42:05 AM7/28/20
to firebird-java

 ..... where dtr.diagTestOrder.id = ....


dual dots in non-quoted identifier? Firebird allows that? 

Can maybe something like fbprofiler.sf.net be used too peep into an actual exchange between an applicatio nand the server at this moment? 

Jim Campana

unread,
Jul 28, 2020, 9:01:50 AM7/28/20
to firebird-java
It does in HQL.

Jim Campana

unread,
Jul 28, 2020, 9:04:11 AM7/28/20
to firebird-java
One very interesting piece I just determined.  The test only fails if the blob field is blank.  If I set it to null, or assign a valid string, then the test passes.

Jim Campana

unread,
Jul 28, 2020, 1:24:02 PM7/28/20
to firebird-java
Tracing through the Jaybird 3.0.9 code, I came across the assignment of the blobId...

In FBLongVarCharField class...

  public Blob getBlob() throws SQLException {
    if (this.blob != null) {
      return this.blob;
    } else if (this.isNull()) {
      return null;
    } else {
      this.blob = new FBBlob(this.gdsHelper, this.getDatatypeCoder().decodeLong(this.getFieldData()));
      return this.blob;
    }
  }

In my case, the "getFieldData()" method returns an empty string, so the "decodeLong" call returns a value of 0, which is assigned as the blobId.

Mark Rotteveel

unread,
Jul 28, 2020, 2:48:56 PM7/28/20
to firebi...@googlegroups.com
On 28-07-2020 14:42, Arioch The wrote:
>
>  ..... where dtr.diagTestOrder.id <http://dtr.diagTestOrder.id> = ....
>
>
> dual dots in non-quoted identifier? Firebird allows that?

This isn't SQL, it is HQL, which is translated to SQL by Hibernate.

Mark
--
Mark Rotteveel

Mark Rotteveel

unread,
Jul 28, 2020, 2:50:12 PM7/28/20
to firebi...@googlegroups.com
I would appreciate an example that is ready to execute, and if possible
using plain JDBC. There are still some missing pieces in the code below
to execute it.

Mark
--
Mark Rotteveel

Mark Rotteveel

unread,
Jul 28, 2020, 3:03:54 PM7/28/20
to firebi...@googlegroups.com
On 28-07-2020 15:04, Jim Campana wrote:
> One very interesting piece I just determined.  The test only fails if
> the blob field is *blank*.  If I set it to null, or assign a valid
> string, then the test passes.

That shouldn't make a difference, a blob with an empty string should
still have blobid. I wonder if this might be the result of some kind of
bug in Firebird where a field is not null and null at the same time (in
which case the field data would report 0 as the blob id, but the field
would not be seen as null).

What is your (full) Firebird version? Is it still reproducable if you
explicitly set the field to an empty string again?

Can you reproduce it with plain JDBC code?

Mark
--
Mark Rotteveel

Mark Rotteveel

unread,
Jul 28, 2020, 3:18:07 PM7/28/20
to firebi...@googlegroups.com
On 28-07-2020 19:24, Jim Campana wrote:
> In my case, the "getFieldData()" method returns an empty string, so the
> "decodeLong" call returns a value of 0, which is assigned as the blobId.

If you connect to the database using ISQL, and execute 'set blobdisplay
off;' followed by a select for the specific blob, what do you see as its
value?

How was this value originally populated?

Mark
--
Mark Rotteveel

Jim Campana

unread,
Jul 29, 2020, 12:37:31 PM7/29/20
to firebird-java
Mark, I think I found the problem, and it comes down to bad data in one blob field in one record in the database.
 
I ran the following query based on your suggestion:
   update diag_test_results set notes = '' where notes = '';


And that fixed the data, and the new jaybird driver (3.0.9) works.

Thank you for your help!

Jim

Mark Rotteveel

unread,
Aug 2, 2020, 2:58:28 PM8/2/20
to firebi...@googlegroups.com
You're welcome. Good to hear you managed to fix the issue!

Mark

PS The latest Jaybird version is 4.0.0 ;)
--
Mark Rotteveel

Mark Rotteveel

unread,
Dec 13, 2023, 7:33:54 AM12/13/23
to firebi...@googlegroups.com
On 27/07/2020 21:42, Jim Campana wrote:
> I am trying to upgrade Jaybird from 2.2.15 to 3.09, and have come across
> an error related to blobs.
> I have a few unit tests that generate a XML document (read from DB), and
> am getting a "blobId must be non-zero for an input blob" error (which I
> found an assertion was introduced in the 3.0 driver.) Has anyone run
> into this issue, and gotten around it?
>
> Configuration for application:
>
> * HikariCP 2.4.4
> * hibernate-core 5.4.2.Final
> * javaVersion 1.8

Just in case someone comes across this thread because they receive the
same error: Jaybird's behaviour was changed in Jaybird 5.0.3 to accept
blob id 0 and request it from the server (which will then treat it as an
empty blob), instead of throwing an exception.

Though theoretically blob id 0 shouldn't occur, in practice they do seem
to occur (possibly due to bugs in Firebird or connection libraries). As
Firebird and fbclient itself considers blob id (semi-)valid and have it
behave as an empty blob, I decide to follow that behaviour (see also
https://github.com/FirebirdSQL/jaybird/issues/764).

Mark
--
Mark Rotteveel

Reply all
Reply to author
Forward
0 new messages