I am developing a survey creator application.

**Survey.java**

```
@Table(name = "SURVEYS")
@Entity
public class Survey implements Serializable{
.
.
.
    @Id
    @Column(name = "ID")
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "genSurvey")
    @SequenceGenerator(name = "genSurvey", sequenceName = "SEQ_SURVEY", allocationSize = 1)
    private Long id;

    @OneToMany(cascade = CascadeType.ALL, mappedBy = "surveyId")
    private Set<Question> questions = new HashSet<Question>();
.
.
.
}

```

**Question.java**

```
@Table(name = "QUESTIONS")
@Entity
public class Question implements Serializable{
.
.
.
    @Id
    @Column(name = "ID")
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "genSurveyQuestions")
    @SequenceGenerator(name = "genSurveyQuestions", sequenceName = "SEQ_SURVEY_QUESTIONS", allocationSize = 1)
    private Long id;

    @ManyToOne
    @JoinColumn(name = "SURVEY_ID")
    private Survey surveyId;
.
.
.
}

```

while adding a new question to a survey I use following code:

**Test.java**

```
survey.getQuestion().add(question1);
survey.getQuestion().add(question2);

currentSession.saveOrUpdate(survey);

```

After running this code I expect it should persist survey and questions. But I get the following errors:

> 
> org.hibernate.exception.ConstraintViolationException: ORA-01400:
>  cannot insert NULL into ("QUESTIONS"."SURVEY\_ID")
> 
> 
> Caused by: java.sql.SQLException: ORA-01400: cannot insert NULL into
>  ("QUESTIONS"."SURVEY\_ID")
> 
> 
> 

Somehow it sets questions' surveyIds to null. What's wrong with my OneToMany association, I couldn't figure out. Any help appriciated.

***Note:*** I used the following link as a reference:
<http://fruzenshtein.com/bidirectional-many-to-one-association/>