How to populate H2 DB UUID primary key using sql file in Spring Boot

Viewed 520

I am developing a Spring Boot-2.4 application which use Spring Data JPA and I am writing test for my CURD implementation. I have few scenarios needs to load table data with specific primary key values before my test execution. I thought of using import.sql or data.sql in which i can write native SQL queries and use those supplied primary key values. As my primary key is defined as UUID eventhough I gave valid UUID data in SQL while fetching using findById its not working.

data.sql insert into TEST_TABLE(id,name,pass) value ('2B12245566587878779679','test','xxxxx');

Assume given UUID value is valid and I can able to insert this data in H2 and able to view. But when in JPA try to access this same ID using findById('2B12245566587878779679') will not returning this record. Is there any correct way to load the UUID and access it using .sql file.

EDIT: Included code sample

@Entity(name="TEST_TABLE")
public class TestTable{

  @Id
  @GeneratedValue
  private UUID id;

}

@Repository
public interface TestTableRepository extends JpaRepository<TestTable,UUID>{}


@Service
public class TestTableService {

  @Autowired
  TestTableRepository testTableRepository;

   public UUID getTableData(UUID id){

    testTableRepository.findById(id); // here passing 2B12245566587878779679

}
}

Expecting one row returned but its not returning any

0 Answers
Related