<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="https://nozaki.me/roller/roller-ui/styles/rss.xsl" media="screen"?><rss version="2.0" 
  xmlns:dc="http://purl.org/dc/elements/1.1/"
  xmlns:atom="http://www.w3.org/2005/Atom" >
<channel>
  <title>Kohei Nozaki&apos;s blog</title>
  <link>https://nozaki.me/roller/kyle/</link>
      <atom:link rel="self" type="application/rss+xml" href="https://nozaki.me/roller/kyle/feed/entries/rss?cat=JPA" />
    <description>Notes of my experiments</description>
  <language>en-us</language>
  <copyright>Copyright 2024</copyright>
  <lastBuildDate>Wed, 1 May 2024 08:28:13 +0000</lastBuildDate>
  <generator>Apache Roller 5.2.0</generator>
        <item>
    <guid isPermaLink="true">https://nozaki.me/roller/kyle/entry/using-jpql-in-clause-with</guid>
    <title>Using JPQL IN clause with composite key</title>
    <dc:creator>Kohei Nozaki</dc:creator>
    <link>https://nozaki.me/roller/kyle/entry/using-jpql-in-clause-with</link>
        <pubDate>Sun, 25 Oct 2015 11:16:44 +0000</pubDate>
    <category>JPA</category>
    <category>eclipselink</category>
    <category>hibernate</category>
    <category>jpa</category>
    <category>jpql</category>
            <description>&lt;div class=&quot;paragraph&quot;&gt;
&lt;p&gt;Assume we have an entity named &lt;code&gt;Employee&lt;/code&gt;:&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;literalblock&quot;&gt;
&lt;div class=&quot;content&quot;&gt;
&lt;pre&gt;@Entity
public class Employee implements Serializable {
    @Id
    @GeneratedValue
    private Long id;
    @Embedded
    private EmployeeName employeeName;

    // accessor omitted&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;paragraph&quot;&gt;
&lt;p&gt;And &lt;code&gt;EmployeeName&lt;/code&gt;:&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;literalblock&quot;&gt;
&lt;div class=&quot;content&quot;&gt;
&lt;pre&gt;@Embeddable
public class EmployeeName implements Serializable {
    private String firstName;
    private String lastName;

    // accessor omitted&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;paragraph&quot;&gt;
&lt;p&gt;Using preceding entity, We want to execute following JPQL:&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;literalblock&quot;&gt;
&lt;div class=&quot;content&quot;&gt;
&lt;pre&gt;SELECT e FROM Employee e WHERE e.employeeName IN :employeeNames&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;paragraph&quot;&gt;
&lt;p&gt;Will it work? It works for Hibernate 4.3.11.Final but unfortunately not for EclipseLink 2.6.1.&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;paragraph&quot;&gt;
&lt;p&gt;Hibernate generates following SQL for the JPQL and the parameter of a &lt;code&gt;List&lt;/code&gt; contains two elements:&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;literalblock&quot;&gt;
&lt;div class=&quot;content&quot;&gt;
&lt;pre&gt;Hibernate: select employee0_.id as id1_0_, employee0_.firstName as firstNam2_0_, employee0_.lastName as lastName3_0_ from Employee employee0_ where employee0_.firstName=? and employee0_.lastName=? or employee0_.firstName=? and employee0_.lastName=?
[Employee{id=1, employeeName=EmployeeName{firstName=&apos;Scott&apos;, lastName=&apos;Vogel&apos;}}, Employee{id=2, employeeName=EmployeeName{firstName=&apos;Nick&apos;, lastName=&apos;Jett&apos;}}]&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;paragraph&quot;&gt;
&lt;p&gt;EclipseLink failed to generate correct SQL for the JPQL. In such case, you need to create a JPQL by hand or Criteria API that uses each column separately (&lt;code&gt;lastName&lt;/code&gt; and &lt;code&gt;firstName&lt;/code&gt;). EclipseLink produces following Exception:&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;literalblock&quot;&gt;
&lt;div class=&quot;content&quot;&gt;
&lt;pre&gt;Exception in thread &quot;main&quot; javax.persistence.PersistenceException: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.6.1.v20150916-55dc7c3): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLDataException: An attempt was made to get a data value of type &apos;BIGINT&apos; from a data value of type &apos;entity.EmployeeName&apos;.
Error Code: 20000
Call: SELECT ID, FIRSTNAME, LASTNAME FROM EMPLOYEE WHERE (ID IN (?,?))
	bind =&amp;gt; [EmployeeName{firstName=&apos;Scott&apos;, lastName=&apos;Vogel&apos;}, EmployeeName{firstName=&apos;Nick&apos;, lastName=&apos;Jett&apos;}]
Query: ReadAllQuery(referenceClass=Employee sql=&quot;SELECT ID, FIRSTNAME, LASTNAME FROM EMPLOYEE WHERE (ID IN ?)&quot;)
	at org.eclipse.persistence.internal.jpa.QueryImpl.getDetailedException(QueryImpl.java:382)
	at org.eclipse.persistence.internal.jpa.QueryImpl.executeReadQuery(QueryImpl.java:260)
	at org.eclipse.persistence.internal.jpa.QueryImpl.getResultList(QueryImpl.java:473)
	at main.Main.main(Main.java:45)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:497)
	at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)
Caused by: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.6.1.v20150916-55dc7c3): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLDataException: An attempt was made to get a data value of type &apos;BIGINT&apos; from a data value of type &apos;entity.EmployeeName&apos;.
Error Code: 20000
Call: SELECT ID, FIRSTNAME, LASTNAME FROM EMPLOYEE WHERE (ID IN (?,?))
	bind =&amp;gt; [EmployeeName{firstName=&apos;Scott&apos;, lastName=&apos;Vogel&apos;}, EmployeeName{firstName=&apos;Nick&apos;, lastName=&apos;Jett&apos;}]
Query: ReadAllQuery(referenceClass=Employee sql=&quot;SELECT ID, FIRSTNAME, LASTNAME FROM EMPLOYEE WHERE (ID IN ?)&quot;)
	at org.eclipse.persistence.exceptions.DatabaseException.sqlException(DatabaseException.java:340)
	at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.basicExecuteCall(DatabaseAccessor.java:684)
	at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeCall(DatabaseAccessor.java:560)
	at org.eclipse.persistence.internal.sessions.AbstractSession.basicExecuteCall(AbstractSession.java:2055)
	at org.eclipse.persistence.sessions.server.ServerSession.executeCall(ServerSession.java:570)
	at org.eclipse.persistence.sessions.server.ClientSession.executeCall(ClientSession.java:258)
	at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:242)
	at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:228)
	at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeSelectCall(DatasourceCallQueryMechanism.java:299)
	at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.selectAllRows(DatasourceCallQueryMechanism.java:694)
	at org.eclipse.persistence.internal.queries.ExpressionQueryMechanism.selectAllRowsFromTable(ExpressionQueryMechanism.java:2740)
	at org.eclipse.persistence.internal.queries.ExpressionQueryMechanism.selectAllRows(ExpressionQueryMechanism.java:2693)
	at org.eclipse.persistence.queries.ReadAllQuery.executeObjectLevelReadQuery(ReadAllQuery.java:559)
	at org.eclipse.persistence.queries.ObjectLevelReadQuery.executeDatabaseQuery(ObjectLevelReadQuery.java:1175)
	at org.eclipse.persistence.queries.DatabaseQuery.execute(DatabaseQuery.java:904)
	at org.eclipse.persistence.queries.ObjectLevelReadQuery.execute(ObjectLevelReadQuery.java:1134)
	at org.eclipse.persistence.queries.ReadAllQuery.execute(ReadAllQuery.java:460)
	at org.eclipse.persistence.queries.ObjectLevelReadQuery.executeInUnitOfWork(ObjectLevelReadQuery.java:1222)
	at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.internalExecuteQuery(UnitOfWorkImpl.java:2896)
	at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1857)
	at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1839)
	at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1804)
	at org.eclipse.persistence.internal.jpa.QueryImpl.executeReadQuery(QueryImpl.java:258)
	... 7 more&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;paragraph&quot;&gt;
&lt;p&gt;Complete source code that has been used in the test can be obtained from &lt;a href=&quot;https://github.com/lbtc-xxx/jpa-composite-in&quot; class=&quot;bare&quot;&gt;https://github.com/lbtc-xxx/jpa-composite-in&lt;/a&gt;&lt;/p&gt;
&lt;/div&gt;</description>          </item>
    <item>
    <guid isPermaLink="true">https://nozaki.me/roller/kyle/entry/working-example-of-eclipselink-static</guid>
    <title>Working example of EclipseLink static weaving</title>
    <dc:creator>Kohei Nozaki</dc:creator>
    <link>https://nozaki.me/roller/kyle/entry/working-example-of-eclipselink-static</link>
        <pubDate>Fri, 23 Oct 2015 18:37:42 +0000</pubDate>
    <category>JPA</category>
    <category>derby</category>
    <category>eclipselink</category>
    <category>jpa</category>
            <description>&lt;div class=&quot;paragraph&quot;&gt;
&lt;p&gt;These days I&amp;#8217;m using EclipseLink at work. It runs on Servlet containers, unfortunately not Java EE containers at there so I have experienced some difference between them. A significant one is class weaving. The dynamic weaving is enabled by default in Java EE containers but not for Java SE environment. Weaving is a prerequisite of using some important functions such as Lazy Loading but it doesn&amp;#8217;t work for default Java SE environment. In Java SE environment, EclipseLink requires a special prerequisite that set an agent in the time of launching JVM, or use static weaving to enable Lazy Loading.&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;paragraph&quot;&gt;
&lt;p&gt;Static weaving offers some performance benefit over Dynamic weaving because it doesn&amp;#8217;t require runtime weaving step. I think it&amp;#8217;s preferable so I tried it over another.&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;sect1&quot;&gt;
&lt;h2 id=&quot;_environment&quot;&gt;Environment&lt;/h2&gt;
&lt;div class=&quot;sectionbody&quot;&gt;
&lt;div class=&quot;ulist&quot;&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;EclipseLink 2.6.1&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Apache Derby 10.12.1.1&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Oracle JDK8u60&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;sect1&quot;&gt;
&lt;h2 id=&quot;_projects&quot;&gt;Projects&lt;/h2&gt;
&lt;div class=&quot;sectionbody&quot;&gt;
&lt;div class=&quot;sect2&quot;&gt;
&lt;h3 id=&quot;_eclipselink_entity&quot;&gt;eclipselink-entity&lt;/h3&gt;
&lt;div class=&quot;paragraph&quot;&gt;
&lt;p&gt;This project contains three simple entity classes. &lt;code&gt;Dept&lt;/code&gt; has many &lt;code&gt;Employee&lt;/code&gt;, and &lt;code&gt;Employee&lt;/code&gt; has one &lt;code&gt;Phone&lt;/code&gt;.&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;sect3&quot;&gt;
&lt;h4 id=&quot;_dept&quot;&gt;Dept&lt;/h4&gt;
&lt;div class=&quot;literalblock&quot;&gt;
&lt;div class=&quot;content&quot;&gt;
&lt;pre&gt;@Entity
public class Dept implements Serializable {
    @Id
    private Long id;
    private String deptName;
    @OneToMany(mappedBy = &quot;dept&quot;)
    private List&amp;lt;Employee&amp;gt; employees;

    // accessors omitted&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;sect3&quot;&gt;
&lt;h4 id=&quot;_employee&quot;&gt;Employee&lt;/h4&gt;
&lt;div class=&quot;literalblock&quot;&gt;
&lt;div class=&quot;content&quot;&gt;
&lt;pre&gt;@Entity
public class Employee implements Serializable {
    @Id
    private Long id;
    @ManyToOne(fetch = FetchType.EAGER) // default
    @JoinColumn(nullable = false)
    private Dept dept;
    private String firstName;
    private String lastName;
    @OneToOne(mappedBy = &quot;employee&quot;, fetch = FetchType.LAZY) // overridden by LAZY
    private Phone phone;

    // accessors omitted&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;paragraph&quot;&gt;
&lt;p&gt;Note that the relation &lt;code&gt;Employee.dept&lt;/code&gt; is set to &lt;code&gt;EAGER&lt;/code&gt;, and &lt;code&gt;Employee.phone&lt;/code&gt; is set to &lt;code&gt;LAZY&lt;/code&gt; as FetchType.&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;sect3&quot;&gt;
&lt;h4 id=&quot;_phone&quot;&gt;Phone&lt;/h4&gt;
&lt;div class=&quot;literalblock&quot;&gt;
&lt;div class=&quot;content&quot;&gt;
&lt;pre&gt;@Entity
public class Phone implements Serializable {
    @Id
    @OneToOne
    @JoinColumn(nullable = false)
    private Employee employee;
    private String phoneNumber;

    // accessors omitted&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;sect3&quot;&gt;
&lt;h4 id=&quot;_persistence_xml&quot;&gt;persistence.xml&lt;/h4&gt;
&lt;div class=&quot;paragraph&quot;&gt;
&lt;p&gt;The persistence descriptor requires a property called &lt;code&gt;eclipselink.weaving&lt;/code&gt; with the value &lt;code&gt;static&lt;/code&gt; to enable static weaving.&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;literalblock&quot;&gt;
&lt;div class=&quot;content&quot;&gt;
&lt;pre&gt;&amp;lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&amp;gt;
&amp;lt;persistence version=&quot;2.1&quot; xmlns=&quot;http://xmlns.jcp.org/xml/ns/persistence&quot;
             xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
             xsi:schemaLocation=&quot;http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd&quot;&amp;gt;
    &amp;lt;persistence-unit name=&quot;myPU&quot; transaction-type=&quot;RESOURCE_LOCAL&quot;&amp;gt;
        &amp;lt;provider&amp;gt;org.eclipse.persistence.jpa.PersistenceProvider&amp;lt;/provider&amp;gt;
        &amp;lt;exclude-unlisted-classes&amp;gt;false&amp;lt;/exclude-unlisted-classes&amp;gt;
        &amp;lt;shared-cache-mode&amp;gt;NONE&amp;lt;/shared-cache-mode&amp;gt;
        &amp;lt;properties&amp;gt;
            &amp;lt;property name=&quot;javax.persistence.jdbc.driver&quot; value=&quot;org.apache.derby.jdbc.EmbeddedDriver&quot;/&amp;gt;
            &amp;lt;property name=&quot;javax.persistence.jdbc.url&quot; value=&quot;jdbc:derby:memory:myDB;create=true&quot;/&amp;gt;
            &amp;lt;property name=&quot;javax.persistence.jdbc.user&quot; value=&quot;app&quot;/&amp;gt;
            &amp;lt;property name=&quot;javax.persistence.jdbc.password&quot; value=&quot;app&quot;/&amp;gt;
            &amp;lt;property name=&quot;javax.persistence.schema-generation.database.action&quot; value=&quot;drop-and-create&quot;/&amp;gt;
            &amp;lt;property name=&quot;eclipselink.weaving&quot; value=&quot;static&quot;/&amp;gt;
            &amp;lt;property name=&quot;eclipselink.logging.level&quot; value=&quot;FINE&quot;/&amp;gt;
            &amp;lt;property name=&quot;eclipselink.logging.parameters&quot; value=&quot;true&quot;/&amp;gt;
        &amp;lt;/properties&amp;gt;
    &amp;lt;/persistence-unit&amp;gt;
&amp;lt;/persistence&amp;gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;sect3&quot;&gt;
&lt;h4 id=&quot;_pom_xml&quot;&gt;pom.xml&lt;/h4&gt;
&lt;div class=&quot;paragraph&quot;&gt;
&lt;p&gt;The static weaving will be done by a convenient Maven plugin. Just put following &lt;code&gt;plugin&lt;/code&gt; definition in your &lt;code&gt;pom.xml&lt;/code&gt; and execute &lt;code&gt;mvn clean install&lt;/code&gt;.&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;literalblock&quot;&gt;
&lt;div class=&quot;content&quot;&gt;
&lt;pre&gt;&amp;lt;build&amp;gt;
    &amp;lt;plugins&amp;gt;
        &amp;lt;plugin&amp;gt;
            &amp;lt;groupId&amp;gt;de.empulse.eclipselink&amp;lt;/groupId&amp;gt;
            &amp;lt;artifactId&amp;gt;staticweave-maven-plugin&amp;lt;/artifactId&amp;gt;
            &amp;lt;version&amp;gt;1.0.0&amp;lt;/version&amp;gt;
            &amp;lt;executions&amp;gt;
                &amp;lt;execution&amp;gt;
                    &amp;lt;phase&amp;gt;process-classes&amp;lt;/phase&amp;gt;
                    &amp;lt;goals&amp;gt;
                        &amp;lt;goal&amp;gt;weave&amp;lt;/goal&amp;gt;
                    &amp;lt;/goals&amp;gt;
                    &amp;lt;configuration&amp;gt;
                        &amp;lt;persistenceXMLLocation&amp;gt;META-INF/persistence.xml&amp;lt;/persistenceXMLLocation&amp;gt;
                        &amp;lt;logLevel&amp;gt;FINE&amp;lt;/logLevel&amp;gt;
                    &amp;lt;/configuration&amp;gt;
                &amp;lt;/execution&amp;gt;
            &amp;lt;/executions&amp;gt;
            &amp;lt;dependencies&amp;gt;
                &amp;lt;dependency&amp;gt;
                    &amp;lt;groupId&amp;gt;org.eclipse.persistence&amp;lt;/groupId&amp;gt;
                    &amp;lt;artifactId&amp;gt;org.eclipse.persistence.jpa&amp;lt;/artifactId&amp;gt;
                    &amp;lt;version&amp;gt;${eclipselink.version}&amp;lt;/version&amp;gt;
                &amp;lt;/dependency&amp;gt;
            &amp;lt;/dependencies&amp;gt;
        &amp;lt;/plugin&amp;gt;
    &amp;lt;/plugins&amp;gt;
&amp;lt;/build&amp;gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;sect2&quot;&gt;
&lt;h3 id=&quot;_eclipselink_example&quot;&gt;eclipselink-example&lt;/h3&gt;
&lt;div class=&quot;paragraph&quot;&gt;
&lt;p&gt;This project is a client of the preceding &lt;code&gt;eclipselink-entity&lt;/code&gt; project. It has a &lt;code&gt;Main&lt;/code&gt; class which simply populates some records then fetches them.&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;literalblock&quot;&gt;
&lt;div class=&quot;content&quot;&gt;
&lt;pre&gt;public class Main {
    public static void main(String[] args) {
        EntityManagerFactory emf = null;
        try {
            emf = Persistence.createEntityManagerFactory(&quot;myPU&quot;);
            EntityManager em = null;

            // Populating data
            try {
                em = emf.createEntityManager();
                final EntityTransaction tx = em.getTransaction();
                tx.begin();

                Dept dept = new Dept();
                dept.setId(1l);
                dept.setDeptName(&quot;Engineering&quot;);
                dept.setEmployees(new ArrayList&amp;lt;&amp;gt;());
                em.persist(dept);

                Employee emp = new Employee();
                emp.setId(1l);
                emp.setFirstName(&quot;Jane&quot;);
                emp.setLastName(&quot;Doe&quot;);
                dept.getEmployees().add(emp);
                emp.setDept(dept);
                em.persist(emp);

                Phone phone = new Phone();
                phone.setPhoneNumber(&quot;000-1111-2222&quot;);
                phone.setEmployee(emp);
                emp.setPhone(phone);
                em.persist(phone);

                tx.commit();
            } finally { if (em != null) { em.close(); } }

            System.out.println(&quot;&amp;lt;&amp;lt;&amp;lt; Populating done &amp;gt;&amp;gt;&amp;gt;&quot;);

            try {
                em = emf.createEntityManager();
                final Employee emp = em.find(Employee.class, 1l);

                System.out.println(emp.getFirstName() + &quot; &quot; + emp.getLastName());

                // EAGER
                System.out.println(emp.getDept().getDeptName());
                // LAZY
                System.out.println(emp.getPhone().getPhoneNumber());
            } finally { if (em != null) { em.close(); } }
        } finally { if (emf != null) { emf.close(); } }
    }
}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;paragraph&quot;&gt;
&lt;p&gt;Here you can see the &lt;code&gt;Phone&lt;/code&gt; entity has lazily fetched while &lt;code&gt;Dept&lt;/code&gt; entity was eagerly fetched:&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;literalblock&quot;&gt;
&lt;div class=&quot;content&quot;&gt;
&lt;pre&gt;&amp;lt;&amp;lt;&amp;lt; Populating done &amp;gt;&amp;gt;&amp;gt;
[EL Fine]: sql: 2015-10-24 03:18:23.389--ServerSession(1216590855)--Connection(1488298739)--Thread(Thread[main,5,main])--SELECT ID, FIRSTNAME, LASTNAME, DEPT_ID FROM EMPLOYEE WHERE (ID = ?)
	bind =&amp;gt; [1]
[EL Fine]: sql: 2015-10-24 03:18:23.408--ServerSession(1216590855)--Connection(1488298739)--Thread(Thread[main,5,main])--SELECT ID, DEPTNAME FROM DEPT WHERE (ID = ?)
	bind =&amp;gt; [1]
Jane Doe
Engineering
[EL Fine]: sql: 2015-10-24 03:18:23.413--ServerSession(1216590855)--Connection(1488298739)--Thread(Thread[main,5,main])--SELECT PHONENUMBER, EMPLOYEE_ID FROM PHONE WHERE (EMPLOYEE_ID = ?)
	bind =&amp;gt; [1]
000-1111-2222&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;paragraph&quot;&gt;
&lt;p&gt;This example uses in-memory Apache Derby so you don&amp;#8217;t need to set up any databases to execute this example. complete projects can be obtained from following GitHub repositories:&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;ulist&quot;&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&quot;https://github.com/lbtc-xxx/eclipselink-entity&quot; class=&quot;bare&quot;&gt;https://github.com/lbtc-xxx/eclipselink-entity&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&quot;https://github.com/lbtc-xxx/eclipselink-example&quot; class=&quot;bare&quot;&gt;https://github.com/lbtc-xxx/eclipselink-example&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;div class=&quot;paragraph&quot;&gt;
&lt;p&gt;Also here&amp;#8217;s &lt;code&gt;build.gradle&lt;/code&gt; example: &lt;a href=&quot;https://github.com/lbtc-xxx/eclipselink-entity/blob/master/build.gradle&quot; class=&quot;bare&quot;&gt;https://github.com/lbtc-xxx/eclipselink-entity/blob/master/build.gradle&lt;/a&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;sect1&quot;&gt;
&lt;h2 id=&quot;_references&quot;&gt;References&lt;/h2&gt;
&lt;div class=&quot;sectionbody&quot;&gt;
&lt;div class=&quot;ulist&quot;&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&quot;http://www.eclipse.org/eclipselink/documentation/2.4/concepts/app_dev007.htm&quot; class=&quot;bare&quot;&gt;http://www.eclipse.org/eclipselink/documentation/2.4/concepts/app_dev007.htm&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&quot;https://wiki.eclipse.org/EclipseLink/UserGuide/JPA/Advanced_JPA_Development/Performance/Weaving/Static_Weaving&quot; class=&quot;bare&quot;&gt;https://wiki.eclipse.org/EclipseLink/UserGuide/JPA/Advanced_JPA_Development/Performance/Weaving/Static_Weaving&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;</description>          </item>
    <item>
    <guid isPermaLink="true">https://nozaki.me/roller/kyle/entry/modifying-persistence-xml-to-execute</guid>
    <title>Modifying persistence.xml to execute drop-and-create dynamically</title>
    <dc:creator>Kohei Nozaki</dc:creator>
    <link>https://nozaki.me/roller/kyle/entry/modifying-persistence-xml-to-execute</link>
        <pubDate>Mon, 23 Mar 2015 06:19:16 +0000</pubDate>
    <category>JPA</category>
    <category>arquillian</category>
    <category>jpa</category>
            <description>&lt;div class=&quot;paragraph&quot;&gt;
&lt;p&gt;I need that for Arquillian testing so I created an utility method for that.&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;paragraph&quot;&gt;
&lt;p&gt;&lt;script src=&quot;https://gist.github.com/lbtc-xxx/109f6bca193f8a99d5ca.js&quot;&gt;&lt;/script&gt;&lt;/p&gt;
&lt;/div&gt;</description>          </item>
    <item>
    <guid isPermaLink="true">https://nozaki.me/roller/kyle/entry/using-jpa-2-1-attributeconverter</guid>
    <title>Using JPA 2.1 AttributeConverter against Java8 LocalDate / LocalDateTime</title>
    <dc:creator>Kohei Nozaki</dc:creator>
    <link>https://nozaki.me/roller/kyle/entry/using-jpa-2-1-attributeconverter</link>
        <pubDate>Tue, 17 Mar 2015 04:50:21 +0000</pubDate>
    <category>JPA</category>
    <category>hibernate</category>
    <category>jpa</category>
            <description>&lt;div class=&quot;paragraph&quot;&gt;
&lt;p&gt;I created an example project using &lt;a href=&quot;https://weblogs.java.net/blog/montanajava/archive/2014/06/17/using-java-8-datetime-classes-jpa&quot; class=&quot;bare&quot;&gt;https://weblogs.java.net/blog/montanajava/archive/2014/06/17/using-java-8-datetime-classes-jpa&lt;/a&gt; which ran on WildFly 8.2.0.Final (Hibernate 4.3.7) and H2 / Apache Derby database.&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;paragraph&quot;&gt;
&lt;p&gt;the whole project can be obtained from &lt;a href=&quot;https://github.com/lbtc-xxx/jpa21converter&quot; class=&quot;bare&quot;&gt;https://github.com/lbtc-xxx/jpa21converter&lt;/a&gt; .&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;paragraph&quot;&gt;
&lt;p&gt;You don&amp;#8217;t need to define any additional configuration in &lt;code&gt;persistence.xml&lt;/code&gt; if you use converters in EE environment. it goes like this:&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;sect1&quot;&gt;
&lt;h2 id=&quot;_the_converter_for_localdate_between_date&quot;&gt;The converter for LocalDate between DATE&lt;/h2&gt;
&lt;div class=&quot;sectionbody&quot;&gt;
&lt;div class=&quot;literalblock&quot;&gt;
&lt;div class=&quot;content&quot;&gt;
&lt;pre&gt;@Converter(autoApply = true)
public class MyLocalDateConverter implements AttributeConverter&amp;lt;java.time.LocalDate, java.sql.Date&amp;gt; {

    @Override
    public java.sql.Date convertToDatabaseColumn(java.time.LocalDate attribute) {
        return attribute == null ? null : java.sql.Date.valueOf(attribute);
    }

    @Override
    public java.time.LocalDate convertToEntityAttribute(java.sql.Date dbData) {
        return dbData == null ? null : dbData.toLocalDate();
    }
}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;sect1&quot;&gt;
&lt;h2 id=&quot;_the_converter_for_localdatetime_between_timestamp&quot;&gt;The converter for LocalDateTime between TIMESTAMP&lt;/h2&gt;
&lt;div class=&quot;sectionbody&quot;&gt;
&lt;div class=&quot;literalblock&quot;&gt;
&lt;div class=&quot;content&quot;&gt;
&lt;pre&gt;@Converter(autoApply = true)
public class MyLocalDateTimeConverter implements AttributeConverter&amp;lt;java.time.LocalDateTime, java.sql.Timestamp&amp;gt; {

    @Override
    public java.sql.Timestamp convertToDatabaseColumn(java.time.LocalDateTime attribute) {
        return attribute == null ? null : java.sql.Timestamp.valueOf(attribute);
    }

    @Override
    public java.time.LocalDateTime convertToEntityAttribute(java.sql.Timestamp dbData) {
        return dbData == null ? null : dbData.toLocalDateTime();
    }
}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;sect1&quot;&gt;
&lt;h2 id=&quot;_entity_class&quot;&gt;Entity class&lt;/h2&gt;
&lt;div class=&quot;sectionbody&quot;&gt;
&lt;div class=&quot;literalblock&quot;&gt;
&lt;div class=&quot;content&quot;&gt;
&lt;pre&gt;@Entity
public class MySimpleTable implements Serializable {
    @Id
    @GeneratedValue
    private Long id;
    private java.time.LocalDateTime someLocalDateTime;
    private java.time.LocalDate someLocalDate;
...&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;paragraph&quot;&gt;
&lt;p&gt;Hibernate produces the DDL against H2 as follows:&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;literalblock&quot;&gt;
&lt;div class=&quot;content&quot;&gt;
&lt;pre&gt;create table MySimpleTable (
    id bigint not null,
    someLocalDate date,
    someLocalDateTime timestamp,
    primary key (id)
)&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;sect1&quot;&gt;
&lt;h2 id=&quot;_using_converters_with_embeddedid&quot;&gt;Using converters with @EmbeddedId&lt;/h2&gt;
&lt;div class=&quot;sectionbody&quot;&gt;
&lt;div class=&quot;paragraph&quot;&gt;
&lt;p&gt;Converters doesn&amp;#8217;t work with fields that annotated as &lt;code&gt;@Id&lt;/code&gt; (see &lt;a href=&quot;http://stackoverflow.com/questions/28337798/hibernate-fails-to-load-jpa-2-1-converter-when-loaded-with-spring-boot-and-sprin&quot; class=&quot;bare&quot;&gt;http://stackoverflow.com/questions/28337798/hibernate-fails-to-load-jpa-2-1-converter-when-loaded-with-spring-boot-and-sprin&lt;/a&gt; ) but works with &lt;code&gt;@EmbeddedId&lt;/code&gt; class.&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;paragraph&quot;&gt;
&lt;p&gt;Entity class:&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;literalblock&quot;&gt;
&lt;div class=&quot;content&quot;&gt;
&lt;pre&gt;@Entity
public class MyCompositeKeyTable implements Serializable {
    @EmbeddedId
    private MyCompositeKeyEmbeddable key;
...&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;paragraph&quot;&gt;
&lt;p&gt;Embeddable class:&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;literalblock&quot;&gt;
&lt;div class=&quot;content&quot;&gt;
&lt;pre&gt;@Embeddable
public class MyCompositeKeyEmbeddable implements Serializable {
    @Column(nullable = false)
    private java.time.LocalDateTime someLocalDateTime;
    @Column(nullable = false)
    private java.time.LocalDate someLocalDate;
...&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;paragraph&quot;&gt;
&lt;p&gt;Produced DDL:&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;literalblock&quot;&gt;
&lt;div class=&quot;content&quot;&gt;
&lt;pre&gt;create table MyCompositeKeyTable (
    someLocalDate date not null,
    someLocalDateTime timestamp not null,
    primary key (someLocalDate, someLocalDateTime)
)&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;</description>          </item>
  </channel>
</rss>