'I need to get all distinct columns from the same table by the same code utilizing Hibernate
I have a table with n x n relationship. That means i have a code that is repeated with only a "brand" column being different between them. The code is not the ID.
I need to have one distinct class that contains all repeatable values and with a list that has all the unique brand column values.I cannot show most of the code samples because of my company security policies. But the entity below is a mock of what i'm seeking.
`
@Entity
@Table(name = "Table")
public class Teste {
@Column(name = "CODE", insertable = false, updatable = false)
private String code;
@Column(name = "NAME")
private String name;
@Column(name = "BRAND")
private String brand;
@OneToMany(cascade = CascadeType.ALL)
@JoinTable(name = "BRAND", joinColumns = { @JoinColumn(name = "CODE"), @JoinColumn(name = "BRAND")})
private Set<Model> brands = new HashSet<>();
@Column(name = "UPDATE_DATE")
private Date update_date;
@Column(name = "EDITOR")
private String editor;
@Id
@Column(name = "ID")
private int id;
}
`
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
