Hibernate: foreign key without entity class, only by id
问题 I have a hierarchical entity, which references it self as a parent. I need to do the mapping only via ids, not via entity instances (the reason is too complicated to explain). So I defined the entity this way: class Item { @Id private String id; @ManyToOne(targetEntity = Item.class) @JoinColumn(name = "PARENT_ID", nullable = true) private String parentId; } This seems to work fine. The foreign key constraint is created correctly in database. But when I execute the following query: SELECT i