This does not directly answer your question but, unless I misunderstood your requirements, what you actually want is to model a self-referencing association, something like this:
@Entity
public class Category {
@Id @GeneratedValue
private Long id;
private String name;
@ManyToOne(optional=true)
private Category parent;
@OneToMany(mappedBy = "parent", cascade = CascadeType.ALL)
private Set<Categories> subCategories;
// ...
public void addToSubCategories(Category category) {
category.setParent(this);
this.subCategories.add(category);
}
}
If this is not what you want, and if you don't want to use a generated identifier, then simply don't use the @GeneratedValue
annotation and assign the identifier manually (in the constructor, using the setter, anything). But I fail to see why you'd need this.