HI I am converting XML file to annotation in Java.For that I have used below annotation code according to XML where we have used collection concept.
This is not related to any of other post which are related to handling null
pointer exception, this is in annotated code I am looking for help.
ANSWER table:
<hibernate-mapping>
<class name="com.sample.Answer"
table="ANSWERS">
<cache usage="read-write"/>
<id name="answerId" type="java.lang.Long">
<column name="ANSWER_ID"/>
<generator class="identity"/>
</id>
<property name="questionId" type="java.lang.Long">
<column name="QUESTION_ID"/>
</property>
<set name="answerText" table="ANSWERTEXT"
inverse="true" fetch="select" lazy="false">
<key>
<column name="ANSWER_ID" not-null="true" />
</key>
<one-to-many class="com.sample.AnswerText" />
</set>
</class>
</hibernate-mapping>
Annotated code:
@Entity
@Table(name = "ANSWERS")
@Cacheable
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
@JsonIgnoreProperties(ignoreUnknown = true)
public class Answer {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "ANSWER_ID")
private Long answerId;
@Column(name = "QUESTION_ID")
private Long questionId;
@OneToMany
@Fetch(FetchMode.SELECT)
private Set<AnswerText> answerText = new HashSet<AnswerText>();
}
ANSWERTEXT table:
<hibernate-mapping>
<class name="com.sample.AnswerText" table="ANSWERTEXT">
<cache usage="read-write"/>
<id name="answerTextId" type="java.lang.Long">
<column name="ANSWER_TEXT_ID"/>
<generator class="identity"/>
</id>
<property name="answerId" type="java.lang.Long">
<column name="ANSWER_ID"/>
</property>
<property name="answerText" type="java.lang.String">
<column name="ANSWER_TEXT"/>
</class>
</hibernate-mapping>
Annotated code:
@Entity
@Table(name = "ANSWERTEXT")
@Cacheable
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
@JsonIgnoreProperties(ignoreUnknown = true)
public class AnswerText {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "ANSWER_TEXT_ID")
private Long answerTextId;
@Column(name = "ANSWER_ID")
private Long answerId;
@Column(name = "ANSWER_TEXT")
private String answerText;
}
Can anybody help me out what is the error I am doing in annotated file, so I am getting null
pointer exception.Please help me on this I am newbie to Java and hibernate.