D
D
dimjava2016-10-16 20:24:38
Java
dimjava, 2016-10-16 20:24:38

How to remove given dependent entity fields from query using hibernate criteria?

There are two classes: A and B and, accordingly, tables in the database corresponding to these classes.
Class B has a LOB field that you don't want to fetch with every request.
How is it possible, by pumping out the list of entities A, to pull out the list of B-nis, but without the data field, and all this using criteria query ?

@Entity  
@Table(name = "A")  
public class A implements Serializable {  
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "id")
    private Long id;

    @OneToMany(mappedBy = "order", fetch = FetchType.LAZY)
    @Cascade(CascadeType.ALL)
    private List<B> list = new LinkedList<>();
}

@Entity  
@Table(name = "B")  
public class B implements Serializable {  
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "id")
    private Long id;

    @Column(name = "data", nullable = false)
    @Lob
    private byte[] data;

    @ManyToOne(targetEntity = A.class, fetch = FetchType.EAGER)
    @JoinColumn(name = "A_id", nullable = false)
    private A a;
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Victor Alenkov, 2016-10-16
@Borz

so fit?

@Entity  
@Table(name = "B")  
public class B implements Serializable {  
...
    @Column(name = "data", nullable = false)
    @Lob
    @javax.persistence.Basic(fetch=FetchType.LAZY)
    private byte[] data;
...
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question