If you are using annotations and have the DB schema:
create table UserExample (
id integer not null auto_increment,
lastName varchar(255),
preName varchar(255),
manager_id integer,
primary key (id)
)
You can use the following annotations setup for your class:
@Entity
public class UserExample {
@Id @GeneratedValue(strategy=GenerationType.AUTO)
private Integer id = null;
@Column(length = 255, nullable = true)
String preName;
@Column(length = 255, nullable = true)
String lastName;
@ManyToOne(cascade={CascadeType.PERSIST, CascadeType.MERGE})
UserExample manager;
@OneToMany(mappedBy = "manager", fetch = FetchType.LAZY, cascade=CascadeType.ALL)
List<UserExample> employees;
}
|