Entity : Details
@OneToMany(mappedBy = "refId")
private Collection<PersonDetail> PersonDetailCollection;
@Id
@Column(name = "REFERENCE_ID")
private String referenceId;
@Column(name = "PRICE_ID")
private String priceID;
@Column(name = "NAME")
private String name;
Getter and Setter of all variable
Entity: PersonDetail
@JoinColumn(name = "REF_ID", referencedColumnName="REFERENCE_ID")
@ManyToOne
private Details refId;
Getter and Setter of all variable
Entity: PriceDetail
@Id
@Column(name = "PRICE_ID")
private String priceID;
@Column(name = "PRICE")
private String price;
Getter and Setter of all variable
Here I have three table from which table Details and PersonDetail have a join. How to get data from these three tables in a single entity without a join on PriceDetail table?
I think what you want is selecting into new object instance using its constructor.
You will have to create a new class, e.g. DetailsResult which would have all the properties you need to retrieve. Then you can use the JPQL query to fetch data:
"select new your.package.DetailsResult(
<fill here the required constructor arguments,
that you will get from the query results, like 'd.referenceId' or 'p.priceID'>)
from Details d, PriceDetail p where d.priceID = p.priceID"
I hope this will put you on the right track.
try writing NamedNativeQuery in the parent class itself. I think this works.!!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With