0

I have an entity setup like this:

@Entity
@Table(name = "APP", uniqueConstraints = @UniqueConstraint(columnNames = "APP_KEY"))
public class Application implements java.io.Serializable {
    ...
    @OneToMany(fetch = FetchType.LAZY)
    @JoinColumn(name = "application_Id", referencedColumnName = "application_Id")
    private Set<Document> documents = new HashSet<Document>(0);
}

Now, in some situations I don't want the list of documents to be returned. However when I serialize this object the "getDocuments()" method will be called.

There will not be an active transaction at this time, so I don't want one of those "no session" errors. I just want to ignore it and have the getDocuments() method return empty, not throw an exception and not try to fetch more data.

Praveen Kumar K S
  • 2,886
  • 1
  • 19
  • 30
Rocky Pulley
  • 21,409
  • 19
  • 65
  • 104
  • I would go for setting empty Set manually after detachment but before serialization. – zbig Jul 18 '14 at 09:35

2 Answers2

0

Take a look at the FetchGroup capability ref:

Take a look at the jpql fetch join's...

Select e from Employee e join fetch e.phones p where p.areaCode = '613'

This was covered for a similar question here: How to properly express JPQL "join fetch" with "where" clause as JPA 2 CriteriaQuery?

Community
  • 1
  • 1
Craig Taylor
  • 1,300
  • 1
  • 9
  • 12
  • I don't think this is what Triton Man is asking for. He doesn't want to fetch but don't want `LazyInitializationException` either. – zbig Jul 18 '14 at 09:29
0

I do not know your serialization setup, however:

jemag
  • 144
  • 1
  • 9