[tag:`XML Approach
<class name="Campaign">
<id name="id" column="cmp_num">
</id>
<one-to-one name="person" property-ref="address" cascade="all"/>
</class>
<class name="MopChangeDocData">
<id name="id" column="mop_cd_data_id">
</id>
<many-to-one name="campaign" column="cmp_id" unique="true"/>
</class>
Table
mop_change_doc_data
With the xml approach application works fine and generates the expected data but with the annotation approach it does not fetching the data.
Annotation Classes
@Entity
@Table(name="parent_cmp")
public class Campaign {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@OneToOne(cascade = CascadeType.ALL)
@JoinColumn(name="cmp_num", referenceColumnName="mop_cd_data_id")
private MopChangeDocData mopChangeDocData;
// getters and setters
}
@Entity
@Table(name="mop_change_doc_data")
public class MopChangeDocData {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@ManyToOne(optional="false")
@JoinColumn(name = "campaign_id")
private Campaign campaign;
// getters and setters
}
I ran both programs, with xml approach it fetches both tables data eg.
select columns..,.. from parent_cmp this_ left out join mop_change_doc_data mop on this_.cmp_num = mop.cmp_id where conditions….
but with the annotation approach its just fetches only parent_cmp data e.g.
select columns…., from parent_cmp this_ where conditions…
Please help me on this how can I achieve the same output from the xml in annotation based classes`]
Faseeh Ahmad is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.