mihalcea_vlad wrote:
You'll have to implement `UserCollectionType` and adapt the logic that's provided in that blog post that I mentioned you.
As I've successfully implemented a raw Integer[] class field based on a database's ARRAY[] column, I've stuck with there's no mention of relationship in the blogpost you've linked. As I understand, I need to implement something like query builder proxy for this new UserType that would compile this special case's queries.
Code:
@Type(type = "i.g.p.t.IntArrayType")
@Column(name = "groups", nullable = false)
private Integer[] groupIds = new Integer[]{};
@OneToMany(targetEntity = Group.class)
@JoinColumn(name = "groups")
private List<Group> groups;
With this code:
- `groupIds` works perfectly just as planned (thanks, your link helped very much)
- `groups` raises SQLProgrammingException with both @JoinColumn(name = "groups") and @JoinColumn(referencedColumnName = "groups") that leads to the fact: query builder tries to query field "groups.groups" (which does not exist). While in this case LAZY loading strategy should produce
Code:
SELECT ... FROM groups WHERE id = any(?) -- here "users.groups" value should be bound as the parameter value
With
Code:
@OneToMany
@JoinColumn(referencedColumnName = "groups", table = "users", name = "id")
private List<Group> groups;
- org.hibernate.AnnotationException: Cannot find the expected secondary table: no users available for i.g.p.m.Group
Could you point me to the docs what should I implement on my own for this type of relationship?