I'm having a bit of a strange problem concerning Java Spring Data JPA Repositories and a SQL Server table I'm working with which has a unique identifier field (the PK field, although the fact that it's a PK is not relevant to the question).
The issue I'm coming across is that, when I insert a new item into this table, the UUID comes back as lowercase. When I do a 'findOne' (using Spring Data pre-2.0) on the table, it also comes back as lowercase, even if the 'findOne' parameter is in uppercase. However, when I do 'findAll' on this table, the IDs all come back as uppercase. I would like to be able to do something like this, for testing:
String id = repository.save(...).getField();
List<String> data = repository.findAll().map(d -> d.getField());
assertThat(data.contains(id));
The problem is that the first line will return a lowercase ID and the second line will return a list of uppercase IDs, so the 3rd line will fail.
As for using Strings for UUIDs, I am aware this is not the recommended practice; however, when I don't do this (when I use the UUID type), I run into a whole different problem which is out of scope for this question. If the recommended answer is "don't use Strings for UUIDs", then I may ask that as a separate question.
Abbreviated table definition:
CREATE TABLE [dbo].[TABLE](
[ID] [uniqueidentifier] NOT NULL,
<...>
CONSTRAINT [PK_Customer] PRIMARY KEY CLUSTERED
(
[ID] ASC
)WITH (STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
ALTER TABLE [dbo].[TABLE] ADD CONSTRAINT [DF_TABLE_ID] DEFAULT (newid()) FOR [ID]
GO
And the entity definition:
@Entity
@Table(name = "TABLE")
public class DataEntity {
@Id
@GeneratedValue(generator = "uuid")
@GenericGenerator(name = "uuid", strategy = "uuid2")
@Column(name = "ID", updatable = false, nullable = false, unique = true)
private String id;
<...>
}