Hibernate ignores property under certain circumstances.

I have a domain object that contains another domain object; call them A and B. B contains a blob (image file), which can be large. So far I only deal with one A at a time when B on A is not a concern. However, sometimes I will deal with thousands of A, in which the transfer around the blob to B leads to the end of the heap. When I deal with so many A, I really don't need Anyway.

Is there a way to tell Hibernate to ignore this property for a specific call? Should I just do transition B and solve the problem of updating / deleting manually in this case?

Right now, to get around this problem, I'm using an SQL query to pull out all the identifiers I want, then iterate over this list, getting each domain object, doing what I need, and then popping it out.

Also, I can't lazy loading B because I'm in a servlet environment, so my Hibernate session is closed before I get access to properties in most cases.

@Entity @Table(name="A") public class A { private Long id @OneToOne(fetch = FetchType.EAGER, cascade = { CascadeType.ALL }, orphanRemoval = true) @JoinColumn(name = "a_id", referencedColumnName = "b_id", nullable = true) @NotFound(action = NotFoundAction.IGNORE) private B b ...getters and setters } @Entity @Table(name="B") public class B { private Long id; private byte[] blob; ...getters and setters } 

thanks

+4
source share
2 answers

Is there a way to tell Hibernate to ignore this property for a specific call? Should I just do transition B and solve the problem of updating / deleting manually in this case?

One option is to use the lazy fetching function (this requires tools for bytecode, see the documentation). So you can map B as follows:

 @Entity @Table(name="B") public class B { @Id private Long id; @Basic(fetch = FetchType.LAZY) @Lob private byte[] blob; // getters and setters } 

And as described:

You can force the usual impatient selection of properties using fetch all properties in HQL.

Another option is to use an alternative version of A (A ') without B for this special use.

References

+7
source

Will I choose an HQL help offer ? With the appropriate constructor added to A , you can return the HQL collection of A with all expected properties b . If I remember correctly, Hibernate Session does not track such partial objects, so updates made to the object will not be cleared to the database. But in your case, since you're getting closer to Session anyway, that might not matter.

+1
source

All Articles