Subject Firebird Spring Data JPA error: user lacks privilege or object not found:
Author

Hi,


I'm getting an error when I try to query a table for data using a Spring Data JPA

I know that my connection is working because I can query using Spring's JdbcTemplate style. I've extracted relevant code below:


T_ACCOUNT DDL table definition:

CREATE GENERATOR GEN_T_ACCOUNT_ID;


CREATE TABLE T_ACCOUNT (

    ID           INTEGER,

    CREDIT_CARD  VARCHAR(16)

);


The entity that I query is called Account.  It is mapped to the T_ACCOUNT defined above.  

Here's an extract of the entity definition:


Account.java


import javax.persistence.Column;

import javax.persistence.Entity;

import javax.persistence.Id;

import javax.persistence.Table;


@Entity

@Table(name="T_ACCOUNT")

public class Account {


@Id

@Column(name="id")

private Long entityId;

@Column(name="CREDIT_CARD")

private String creditCardNumber;


public Account() {

}


/**

* Getter for the credit card number for this account.

* @return the credit card number for this account as a 16-character String.

*/

public String getCreditCardNumber() {

return creditCardNumber;

}


/**

* Setter for the credit card number for this account.

* @param creditCardNumber

*/

public void setCreditCardNumber(String creditCardNumber) {

this.creditCardNumber = creditCardNumber;

}

/** 

* Returns the id for this account.

*/

public Long getEntityId() {

return entityId;

}

/**

* Sets the id for this account. Package local - only available to tests.

*/

void setEntityId(Long entityId) {

this.entityId = entityId;

}


}


Here's the Spring Data Repository that will be used to run basic CRUD operations on the Account entity

AccountRepository.java:


import org.springframework.data.repository.Repository;


public interface AccountRepository extends Repository<Account, Long> {


public Account findByCreditCardNumber(String creditCardNumber);


}


The repository gets wired into the implementation as follows:

public class RewardNetworkImpl implements RewardNetwork {


private AccountRepository accountRepository;


/**

* Creates a new reward network.

* @param accountRepository the repository for loading accounts to reward

*/

public RewardNetworkImpl(AccountRepository accountRepository) {

this.accountRepository = accountRepository;

}


For System Testing I add two config classes:

One for basic configuration and one for System Testing:

My Spring DataSource Configuration:

import javax.sql.DataSource;


import org.apache.commons.dbcp.BasicDataSource;

import org.springframework.context.annotation.Bean;

import org.springframework.context.annotation.Configuration;

import org.springframework.data.jpa.repository.config.EnableJpaRepositories;

import org.springframework.transaction.annotation.EnableTransactionManagement;


import rewards.RewardNetwork;

import rewards.internal.RewardNetworkImpl;

import rewards.internal.account.AccountRepository;



@Configuration

@EnableTransactionManagement

@EnableJpaRepositories(basePackages="rewards")

public class RewardsConfig {


DataSource dataSource = createTestDataSource();

@Bean

public RewardNetwork rewardNetwork(

AccountRepository accountRepository ) {

return new RewardNetworkImpl(

accountRepository, 

restaurantRepository, 

rewardRepository);

}


@Bean

public RewardRepository rewardRepository(){

repository.setDataSource(dataSource);

return repository;

}

    public DataSource createTestDataSource() {

   

        BasicDataSource dataSource = new BasicDataSource();

        dataSource.setUrl("jdbc:firebirdsql://localhost:3050/C:/db/my.fdb");

        dataSource.setDriverClassName("org.firebirdsql.jdbc.FBDriver");

        dataSource.setUsername("SYSDBA");

        dataSource.setPassword("masterkey");

        dataSource.setConnectionProperties("charSet=utf-8");

        return dataSource;

        

    }

}


SystemTestConfig is used to wire the configuration together for testing:

package rewards;


import org.springframework.boot.autoconfigure.EnableAutoConfiguration;

import org.springframework.boot.autoconfigure.domain.EntityScan;

import org.springframework.context.annotation.Configuration;

import org.springframework.context.annotation.Import;


import config.RewardsConfig;


@Configuration

@EntityScan("rewards")

@EnableAutoConfiguration

@Import(RewardsConfig.class)

public class SystemTestConfig {}


Finally, a test stub that calls AccountRepository.findByCreditCardNumber() method:

Account account = accountRepository.findByCreditCardNumber("1234");


When I invoke the findByCreditCardNumber method I get the following Hibernate Error:

ERROR: o.h.engine.jdbc.spi.SqlExceptionHelper - user lacks privilege or object not found: 


T_ACCOUNT in statement 

[select account0_.id as id1_0_, account0_.credit_card as credit_c2_0_

from t_account account0_ 

where account0_.credit_card=?]


The SQL looks correct to me and I can invoke it directly on the database using IBExpert.  I also made note that the Credit Card Number is valid and is already present in the database.  If I query using JdbcTemplate, everything just works but I'd like to be able to use Spring Data JPA for lots of reasons.


This is for a Firebird 1.5 Database using jaybird-jdk18-2.2.10.jar.