Java Developer
Java Developer

Reputation: 1901

How to map child class with Parent class in Hibernate?

In my Hibernate Pojo classes i'm using like this..

@Entity
@Table(name="EC_TIMETABLE")
public class TimetableVO{
@ManyToOne
@JoinColumn(name="SKILLSET_ID", insertable=false, updatable=false)
private SkillsetVO skillset;
...
...
}

and Another Bean

@Entity
@Table(name="EC_SKILLSET")
public class SkillsetVO{

    @ManyToOne
    @JoinColumn(name="USER_ID", insertable=false, updatable=false)
    private UserVO user;

    @ManyToOne
    @JoinColumn(name="COURSE_ID", insertable=false, updatable=false)
    private CourseVO course;
}

And my user Bean..

@Entity
@Table(name = "EC_USER")
public class UserVO extends AbstractVO {
@OneToMany(mappedBy = "user", fetch = FetchType.EAGER)
    private Set<SkillsetVO> skillset;
}

And in my Service class just i'm inserting the bean..

@Transactional
public void createEvent(TimetableVO timetableVO) throws DataAccessException {
        System.out.println(timetableVO.getSkillset().getId());//Hear id is P.K in SkillSetVO
    entityManager.persist(timetableVO);
}

Hear The output Statement Print "S1" But in the Database it is showing NULL...

So is their any Wrong Mapping i set into Bean Classes?

Upvotes: 3

Views: 940

Answers (1)

Subin Sebastian
Subin Sebastian

Reputation: 10997

@ManyToOne
@JoinColumn(name="SKILLSET_ID", insertable=false, updatable=false)
private SkillsetVO skillset;

try removing insertable=false

Upvotes: 3

Related Questions