1
public class Test{
    @Id
    @JsonIgnore
    @GeneratedValue(generator = "uuid2")
    @GenericGenerator(name = "uuid2", strategy = "uuid2")
    @Column(name="TEST_ID",columnDefinition = "BINARY(16)")
    @Type(type="uuid-binary")
    //@Column(name="TEST_ID",columnDefinition = "BINARY(32)")
    //@Type(type="uuid-char")
    private UUID testId;

    @Id
    @JsonIgnore
    @GeneratedValue(generator = "uuid2")
    @GenericGenerator(name = "uuid2", strategy = "uuid2")
    @Column(name="USER_ID",columnDefinition = "BINARY(16)")
    //@Column(name="USER_ID",columnDefinition = "BINARY(32)")
    //@Type(type="uuid-binary") //@Type(type="uuid-char")
    private UUID userId;

    public void setTestId(UUID testId) {
        this.testId = testId;
    }

    public UUID getTestId() {
        return testId;
    }    

}

Save the data in the DB. The UUID is saving as BLOB in the DB. Error while getting the ID from the DB

test.setTestId( UUID.nameUUIDFromBytes((byte[]) row[0]));

Mysql Table:

DROP TABLE IF EXISTS `DBName`.`testtable` ;
CREATE TABLE IF NOT EXISTS `DBName`.`testtable` (
`test_id` binary(16) NOT NULL,
`user_id` binary(16) NOT NULL,
`company_id` VARCHAR(45) NOT NULL,
PRIMARY KEY (`test_id`),
UNIQUE KEY `company_test_id` (`company_id`, `test_id`))
ENGINE = InnoDB;

solutions tried :

//@Column(name="TEST_ID",columnDefinition = "BINARY(32)")
//@Type(type="uuid-binary") //@Type(type="uuid-char")

Nothing worked.

Shadow
  • 33,525
  • 10
  • 51
  • 64
Veds
  • 11
  • 1
  • 6
  • Get Query by testID is not working as expected. Query q = em.createNativeQuery("select fd.test_id, fd.company_id " + " from testtable tt" + " where tt.company_id = :companyid and tt.test_id = :testId "); q.setParameter("companyid",companyid); q.setParameter("testId",testId); How to use Unhex in this Hibernate query – Veds May 18 '17 at 22:46

0 Answers0