user2046810
user2046810

Reputation: 393

JPA join column only for insert/delete , disable select

I have @OneToMAny realationship inside my entity.

Is it possible to disable jpa from generating select for the joined column? beacuse I have many records in my main table and when selecting them , each record performs select for the joined column. I would like to disable this select is that possible?

UPDATE: I tried inserting fetch LAZY but it still creates a select for Table02f and Table03f...

This is my code:

 public class Table01f implements Serializable {

    @OneToMany(fetch=FetchType.LAZY , cascade = CascadeType.ALL, mappedBy = "table01f")
    private List<Table02f> table02fList;

    //getter & setter...
}

public class Table02f implements Serializable {

    @JoinColumn(name = "F2PRP", referencedColumnName = "F1PRP", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    @JsonIgnore
    private Table01f table01f;

    @OneToMany(fetch=FetchType.LAZY , cascade = CascadeType.ALL, mappedBy = "table02f")
    private List<Table03f> table03fList;

    //getter & setter...
}

public class Table03f implements Serializable {

    @JoinColumns({
        @JoinColumn(name = "F3PRP", referencedColumnName = "F2PRP", insertable = false, updatable = false),
        @JoinColumn(name = "F3BRN", referencedColumnName = "F2BRN", insertable = false, updatable = false)})
    @ManyToOne(optional = false)
    @JsonIgnore
    private Table02f table02f;

//getter & setter...
}

Thank's In Advance.

Upvotes: 1

Views: 1796

Answers (2)

James
James

Reputation: 18389

If you don't need the data make it LAZY (in general always make everything LAZY).

If you need the data, then you can use batch fetching, or join fetching.

http://java-persistence-performance.blogspot.com/2010/08/batch-fetching-optimizing-object-graph.html

Upvotes: 1

eternay
eternay

Reputation: 3814

Just add the fetch type LAZY to your @OneToMany relationship:

@OneToMany(fetch=FetchType.LAZY)

When you load the list of your main entities, JPA won't populate your list for this relationship, avoiding the generation of the SELECT.

Just have a look at this functionality in JPA documentation so that you can understand how to use it.

Upvotes: 3

Related Questions