ctudose / java-persistence-spring-data-hibernate

54 stars 43 forks source link

`@NotNull`’s query behavior depends on the presence of `javax.el` dependency #7

Open mklinkj opened 3 months ago

mklinkj commented 3 months ago

Hello

For consistency of execution behavior between the main environment and the test environment, I would like to ask whether it would be better to add javax.el to the test dependency in an environment using Hibernate Validtor.

For example, in the eagerjoin example in Chapter 12, @NotNull is appended as follows:

However, if you run the test after including the following content in pom.xml...

<dependency>
  <groupId>org.glassfish</groupId>
  <artifactId>javax.el</artifactId>
  <version>3.0.0</version>
  <scope>test</scope>
</dependency>

The execution result is as follows:

Hibernate: 
    select
        item0_.id as id1_1_0_,
        item0_.auctionEnd as auctione2_1_0_,
        item0_.name as name3_1_0_,
        item0_.seller_id as seller_i4_1_0_,
        bids1_.item_id as item_id4_0_1_,
        bids1_.id as id1_0_1_,
        bids1_.id as id1_0_2_,
        bids1_.amount as amount2_0_2_,
        bids1_.bidder_id as bidder_i3_0_2_,
        bids1_.item_id as item_id4_0_2_,
        user2_.id as id1_2_3_,
        user2_.username as username2_2_3_ 
    from
        Item item0_ 
    left outer join
        Bid bids1_ 
            on item0_.id=bids1_.item_id 
    inner join  -- // 💡Query executed with INNER JOIN for seller
        USERS user2_ 
            on item0_.seller_id=user2_.id 
    where
        item0_.id=?

In this case, @NotNull was processed normally and the INNER JOIN query was executed with the mandatory condition that the Item must contain a User.

Generally, in the main environment, javax.el is included in WAS such as Tomcat, so that part is likely to be executed as INNER JOIN.

I asked because I thought that if your project uses annotations such as Hibernate Validator and @NotNull, it would be better to add javax.el to the test dependencies in the test environment to ensure the same behavior as the main environment.

thank you have a good day. 👍