| As documented in this forum thread, SQL Server uses an uppercase representation for UUIDs. If we use the UUID or byte[] UUID identifiers, everything works just fine. But if we use a String identifier, then the UUID.toString() will return a lowercase String representation (which is according to the UUID specs). However, SQL Server uses an uppercase UUID String representation, and this can cause issues when fetching FK associations. After analyzing this issue, I came to realize that, instead of fixing anything in Hibernate, the user can workaround this SQL Server limitation by using an uppercase identifier:
@Entity
@Table(name = "foo")
public static class FooEntity {
@Id
@GenericGenerator(name = "uuid", strategy = "uuid2")
@GeneratedValue(generator = "uuid")
@Column(columnDefinition = "UNIQUEIDENTIFIER")
private String id;
@ElementCollection
@JoinTable(name = "foo_values")
@Column(name = "foo_value")
private final Set<String> fooValues = new HashSet<>();
public String getId() {
return id.toUpperCase();
}
public void setId(String id) {
this.id = id;
}
public Set<String> getFooValues() {
return fooValues;
}
}
This will work for field-based access. For property-based access, you could use a byte[] for the identifier, and have a method to transform the byte[] to a String for the UI. Just make sure that, internally, the byte[] is used, not the String one. |