Ebean generating wrong SQL


#1

I am using Play framework 2.5 with ebean.

I have query, that takes a contract, that has one of these 2 attached (a request or building):

	ContractRental contract = ContractRental.find
			.where().
					and(
							Expr.or(
									Expr.eq("request.domainRegister.domainId", domainId),
									Expr.eq("domainBuilding.domainImmovable.domainProperty.domainRegister.domainId", domainId)),
							Expr.eq("contractRentalId", contractId)
					)
			.findUnique();

The generated joins look like this.

 from contract_rental t0 
 left outer join domain_building t1 on t1.building_id = t0.building_id 
 join domain_immovable t2 on t2.immovable_id = t1.immovable_id 
 join domain_property t3 on t3.property_id = t2.property_id 
 left outer join request t4 on t4.contract_id = t0.contract_rental_id 

The problem is that, since there are normal(left) joins before the last left outer join, the values are already filtered.

The query does work correctly, when I change it to

 from contract_rental t0 
 left outer join domain_building t1 on t1.building_id = t0.building_id 
 left outer join domain_immovable t2 on t2.immovable_id = t1.immovable_id 
 left outer join domain_property t3 on t3.property_id = t2.property_id 
 left outer join request t4 on t4.contract_id = t0.contract_rental_id 

But this means I have to make my domain_immovable nullable true, but that is not the case.

@ManyToOne (fetch=FetchType.LAZY)
@JoinColumn(name="immovable_id", nullable=false,  unique=false  )
@Required
private DomainImmovable domainImmovable;

Any tips to get it working?


(Marcos Pereira) #2

Hi @sjaanus,

Better to raise the question with Ebean community:

http://ebean-orm.github.io/support

It could be good to create an isolated reproducer (not involving Play) if you think it is a bug and also test with a recent version.

Best.


#3

I upgraded to the play-ebean framework to 3.2.0 and it now works correctly.

Only interesting thing is that now instead of 1 query, it generates 10+ queries, but I guess its related to new ebean.