0

I have an entity Application.java, which in turn has a property

@Audit(changeTracker = AttributeValueListChangeTracker.class)
    @OneToMany(cascade = { CascadeType.ALL }, orphanRemoval = true, targetEntity = AttributeValue.class)
    @OrderBy
    @JoinColumn(name = "application_id")
    @LazyCollection(LazyCollectionOption.FALSE)
    private List<AttributeValue> attributeValueList = new ArrayList<AttributeValue>();

This eager fetching of this property is posing a problem in performance. I cannot make it lazy as in some cases eager fetch is required. The case on which I am working doesn't require eager fetch. is there a way to make this property load lazy just for my case?

Shruti Rawat
  • 687
  • 6
  • 11
  • 24
  • You realise lazy is just a "hint" and you should first check whether your database implementation enables that? –  Feb 24 '15 at 06:37

1 Answers1

0

You can write custom fetch method either via HQL or let's say Spring Data JPA which would not blindly go for whole entity (and it's eager relationships) but for certain properties which your case requires...

rikica
  • 351
  • 2
  • 11
  • I actually wanted to avoid that. Application entity has >10 properties out of which i just want to avoid this particular one. – Shruti Rawat Feb 24 '15 at 06:55
  • Then you probably saw this [link](http://stackoverflow.com/questions/14701386/exclude-loading-of-specific-properties-in-hibernate-object) and this [link](http://stackoverflow.com/questions/2934753/avoiding-secondary-selects-or-joins-with-hibernate-criteria-or-hql-query). I'm afraid that's the only possibility if field **must** stay eagerly loaded by default... – rikica Feb 24 '15 at 10:41