I have below scenario
Entity TableA :
@Entity @Table(name = "TABLE_A") @NamedQueries({ @NamedQuery(name = "TableA.namedQ1", query = "SELECT t1 FROM TableA t1 JOIN FETCH t2.TableB t2" + " WHERE <conditions here>"), @NamedQuery(<Need query here which will ignore mapping below and return rows only for TableA>) } ) public class TableA implements Serializable{ @Id @Column(name = "id") private int id ... ... ... @OneToMany(mappedBy = "tableA", cascade = CascadeType.ALL ,fetch=FetchType.LAZY) private List<TableB> tableB; }
Entity TableB :
@Entity @Table(name = "TABLE_B") public class TableB implements Serializable{ @Id @Column(name = "id1") private int id1 ... ... ... @ManyToOne @JoinColumn(name = "id",insertable = false, updatable = false) private TableA tableA; }
I am facing below two issues :
Query mentioned above i.e
SELECT t1 FROM TableA t1 JOIN FETCH t2.TableB t2
takes long time to execute. around 30 seconds. But the same query for same dataset takles hardly 3-4 seconds in SQL developer. ANythnig I should do in code to make it run faster?
I have requirement where i dont need data from other table(retrived via mapping). I would be needing data only from TableA. I tried below named query but it run separate query against TableB for each row in TableA which takes 4+ minutes to execute.
"SELECT t1 FROM TableA t1 where <condition goes here>"
What modifications I have to do in query to ignore mapping. I would need to retain annotations(@OneToMany) as I will need it in namedQ1.
Thanks in anticipation