@@ -36,7 +36,7 @@ We use the following Entity classes to show you some examples:
3636 @Transient private Employee manager;
3737 @Transient private Address address;
3838
39- // getter and setter
39+ // getters and setters
4040 }
4141
4242 .. code-block :: java
@@ -52,14 +52,50 @@ We use the following Entity classes to show you some examples:
5252 @OriginalStates private Department originalStates;
5353 @Transient private List<Employee > employeeList = new ArrayList<> ();
5454
55- // getter and setter
55+ // getters and setters
5656 }
5757
58- Note that both of the above classes are annotated with ``@Entity(metamodel = @Metamodel) ``.
58+ .. code-block :: java
59+
60+ @Entity (immutable = true , metamodel = @Metamodel )
61+ @Table (name = " EMPLOYEE" )
62+ public class Emp {
63+
64+ @Id private final Integer employeeId;
65+ private final Integer employeeNo;
66+ private final String employeeName;
67+ private final Integer managerId;
68+ private final LocalDate hiredate;
69+ private final Salary salary;
70+ private final Integer departmentId;
71+ private final Integer addressId;
72+ @Version private final Integer version;
73+ @Transient private final Dept department;
74+ @Transient private final Emp manager;
75+
76+ // constructor and getters
77+ }
78+
79+ .. code-block :: java
80+
81+ @Entity (immutable = true , metamodel = @Metamodel )
82+ @Table (name = " DEPARTMENT" )
83+ public class Dept {
84+
85+ @Id private final Integer departmentId;
86+ private final Integer departmentNo;
87+ private final String departmentName;
88+ private final String location;
89+ @Version private final Integer version;
90+
91+ // constructor and getters
92+ }
93+
94+ Note that the above classes are annotated with ``@Entity(metamodel = @Metamodel) ``.
5995The ``metamodel = @Metamodel `` indicates that the annotated entity
6096has a corresponding metamodel class generated by Doma's annotation processor .
6197
62- In our examples, the metamodel classes are ``Employee_ `` and ``Department_ ``.
98+ In our examples, the metamodel classes are ``Employee_ ``, `` Department_ ``, `` Emp_ `` and ``Dept_ ``.
6399These metamodels allow you to make your query typesafe.
64100
65101You can customize the name of the metamodels by the Metamodel annotation elements.
@@ -456,6 +492,12 @@ We support the following operators and predicates:
456492* exists
457493* notExists - (not exists)
458494
495+ .. note ::
496+
497+ The ``eq `` operator generates the ``is null `` predicate if the second operand is ``null ``.
498+ Also, the ``ne `` operator generates the ``is not null `` predicate if the second operand is ``null ``.
499+
500+
459501We also support the following logical operators:
460502
461503* and
@@ -661,6 +703,42 @@ You can associate many entities:
661703 .associate(e, a, Employee :: setAddress)
662704 .fetch();
663705
706+ association for immutable entities (Entityql)
707+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
708+
709+ You can associate immutable entities with the ``associateWith `` operation in the Entityql DSL.
710+ You have to use the ``associateWith `` operation with join expression.
711+
712+ .. code-block :: java
713+
714+ Emp_ e = new Emp_ ();
715+ Emp_ m = new Emp_ ();
716+ Dept_ d = new Dept_ ();
717+
718+ List<Emp > list =
719+ entityql
720+ .from(e)
721+ .innerJoin(d, on - > on. eq(e. departmentId, d. departmentId))
722+ .leftJoin(m, on - > on. eq(e. managerId, m. employeeId))
723+ .where(c - > c. eq(d. departmentName, " SALES" ))
724+ .associateWith(e, d, Emp :: withDept)
725+ .associateWith(e, m, Emp :: withManager)
726+ .fetch();
727+
728+ The above query issues the following SQL statement:
729+
730+ .. code-block :: sql
731+
732+ select t0_.EMPLOYEE_ID, t0_.EMPLOYEE_NO, t0_.EMPLOYEE_NAME, t0_.MANAGER_ID, t0_.HIREDATE,
733+ t0_.SALARY, t0_.DEPARTMENT_ID, t0_.ADDRESS_ID, t0_.VERSION,
734+ t1_.DEPARTMENT_ID, t1_.DEPARTMENT_NO, t1_.DEPARTMENT_NAME, t1_.LOCATION, t1_.VERSION,
735+ t2_.EMPLOYEE_ID, t2_.EMPLOYEE_NO, t2_.EMPLOYEE_NAME, t2_.MANAGER_ID, t2_.HIREDATE,
736+ t2_.SALARY, t2_.DEPARTMENT_ID, t2_.ADDRESS_ID, t2_.VERSION
737+ from EMPLOYEE t0_
738+ inner join DEPARTMENT t1_ on (t0_.DEPARTMENT_ID = t1_.DEPARTMENT_ID)
739+ left outer join EMPLOYEE t2_ on (t0_.MANAGER_ID = t2_.EMPLOYEE_ID)
740+ where t1_.DEPARTMENT_NAME = ?
741+
664742 Dynamic join expression (Entityql, NativeSql)
665743~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
666744
@@ -1092,6 +1170,7 @@ We support the following settings:
10921170* queryTimeout
10931171* sqlLogType
10941172* batchSize
1173+ * excludeNull
10951174
10961175They are all optional.
10971176
@@ -1108,6 +1187,7 @@ You can apply them as follows:
11081187 settings. setQueryTimeout(1000 );
11091188 settings. setSqlLogType(SqlLogType . RAW );
11101189 settings. setBatchSize(20 );
1190+ settings. excludeNull(true );
11111191 })
11121192 .values(
11131193 c - > {
@@ -1227,6 +1307,7 @@ We support the following settings:
12271307* queryTimeout
12281308* sqlLogType
12291309* suppressOptimisticLockException
1310+ * excludeNull
12301311
12311312They are all optional.
12321313
@@ -1244,6 +1325,7 @@ You can apply them as follows:
12441325 settings. setQueryTimeout(1000 );
12451326 settings. setSqlLogType(SqlLogType . RAW );
12461327 settings. setSuppressOptimisticLockException(true );
1328+ settings. excludeNull(true );
12471329 }). set(c - > {
12481330 c. value(e. employeeName, " aaa" );
12491331 }). execute();
0 commit comments