Reputation: 3552
Suppose I have the following objects (one table per object) with this relations: A -> B -> C -> D
If I findById an instance of A, all B, C and D are returned which is not I want. Is this possible to force Hibernate only to return A (or only it's primitive properties)?
I know that I can write "SELECT a.x, a.y, a.z, ... FROM A"
and then manually put the result list of objects in A, but this is somewhat timely as I should manually fill all properties. I have also checked all Hibernate query hints but nothing related.
Mohsen
Upvotes: 1
Views: 2727
Reputation: 5628
If you have a constructor for A which fills all fields except the ones you don't want to join, you could select like this:
SELECT NEW A(a.x, a.y, a.z) FROM A a
Upvotes: 2
Reputation: 2936
You can specify fetch="select" and lazy="true" in your mapping. Especially if your relations -> are lists.
Upvotes: 1
Reputation: 26597
select a from A a ?
also, how have you've mapped your relations? lazy="proxy" and fetch="join"?
Upvotes: 2