Is it possible to join two classes without specified mapping between them (using Criteria API)?
I must join two classes and retrieve data from both but I can't mapping them. I know only foreign key SomeID in the first class and primary key ID in second.
How to create Criteria to join them? Is it possible without mapping?
Please, help, I'm really need it but I'm stuck. :/
PS
I know 'any' mapping but I have 10 fields like SomeID. Creating any mappings for 10 fields only for creating joins is overkill. If there is no other resolution I'll do it but I don't want to.
I don't know the criteria version, but in HQL you can do it like this:
select customer, order from Customer customer, Order order
where order.CustomerID = customer.Id
and customer.Id = 42
The result set will then be a list of object[] where the customer will be repeated times the number of orders he has placed (assuming of course that there is one customer to many orders).
Please note that the result will be empty if there aren't any ordes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With