{"id":127379,"date":"2024-10-17T17:06:00","date_gmt":"2024-10-17T14:06:00","guid":{"rendered":"https:\/\/www.javacodegeeks.com\/?p=127379"},"modified":"2024-10-15T10:56:58","modified_gmt":"2024-10-15T07:56:58","slug":"spring-data-dynamicinsert-annotation-example","status":"publish","type":"post","link":"https:\/\/www.javacodegeeks.com\/spring-data-dynamicinsert-annotation-example.html","title":{"rendered":"Spring Data DynamicInsert Annotation Example"},"content":{"rendered":"<h2 class=\"wp-block-heading\">1. Introduction<\/h2>\n<p><a href=\"https:\/\/docs.spring.io\/spring-data\/jpa\/reference\/index.html\" target=\"_blank\" rel=\"noreferrer noopener\">Spring Data JPA<\/a> supports common <a href=\"https:\/\/docs.oracle.com\/javaee\/6\/tutorial\/doc\/bnbpz.html\" target=\"_blank\" rel=\"noreferrer noopener\">JPA<\/a> providers, e.g. <a href=\"https:\/\/hibernate.org\/orm\/documentation\/6.6\/\" target=\"_blank\" rel=\"noreferrer noopener\">Hibernate<\/a>, EclipseLink, etc. Hibernate pre-generates and caches static SQL insert statements that include every mapped column by default. The <a href=\"https:\/\/docs.redhat.com\/en\/documentation\/red_hat_jboss_web_server\/1.0\/html\/hibernate_annotations_reference_guide\/entity-hibspec#entity-hibspec\" target=\"_blank\" rel=\"noreferrer noopener\">@org.hibernate.annotations.DynamicInsert<\/a> overwrites the default implementation and dynamically generates the insert SQL statement for non-null fields at runtime. In this example, I will demonstrate the Spring Data <code>DynamicInsert<\/code> annotation with a simple Spring boot application.<\/p>\n<h2 class=\"wp-block-heading\">2. Setup<\/h2>\n<p>In this step, I will create a gradle project for Java 17 along with <code>lombok<\/code>, Spring Data JPA, H2 database, and <code>Junit<\/code> libraries. The project is generated by <a href=\"https:\/\/start.spring.io\/\">Spring initializer<\/a> with the details outlined in Figure 1.<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><a href=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2024\/10\/createProject.jpg\"><img decoding=\"async\" width=\"793\" height=\"607\" src=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2024\/10\/createProject.jpg\" alt=\"Spring Data DynamicInsert\" class=\"wp-image-127401\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2024\/10\/createProject.jpg 793w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2024\/10\/createProject-300x230.jpg 300w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2024\/10\/createProject-768x588.jpg 768w\" sizes=\"(max-width: 793px) 100vw, 793px\" \/><\/a><figcaption class=\"wp-element-caption\">Figure 1 Create a Project<\/figcaption><\/figure>\n<\/div>\n<h3 class=\"wp-block-heading\">2.1 Generated Files<\/h3>\n<p>In this step, I will show three generated files. No modification is needed for this example.<\/p>\n<p>The generated <code>build.gradle<\/code> file includes needed libraries.<\/p>\n<p><span style=\"text-decoration: underline\"><em>build.gradle<\/em><\/span><\/p>\n<pre class=\"brush:plain\">plugins {\n\tid 'java'\n\tid 'org.springframework.boot' version '3.3.4'\n\tid 'io.spring.dependency-management' version '1.1.6'\n}\n\ngroup = 'org.jcg.zheng'\nversion = '0.0.1-SNAPSHOT'\n\njava {\n\ttoolchain {\n\t\tlanguageVersion = JavaLanguageVersion.of(17)\n\t}\n}\n\nconfigurations {\n\tcompileOnly {\n\t\textendsFrom annotationProcessor\n\t}\n}\n\nrepositories {\n\tmavenCentral()\n}\n\ndependencies {\n\timplementation 'org.springframework.boot:spring-boot-starter-data-jpa'\n\tcompileOnly 'org.projectlombok:lombok'\n\truntimeOnly 'com.h2database:h2'\n\tannotationProcessor 'org.projectlombok:lombok'\n\ttestImplementation 'org.springframework.boot:spring-boot-starter-test'\n\ttestRuntimeOnly 'org.junit.platform:junit-platform-launcher'\n}\n\ntasks.named('test') {\n\tuseJUnitPlatform()\n}<\/pre>\n<p>The generated <code>DynamicinsertApplication.java<\/code> file.<\/p>\n<p><span style=\"text-decoration: underline\"><em>DynamicinsertApplication.java<\/em><\/span><\/p>\n<pre class=\"brush:java\">package org.jcg.zheng.dynamicinsert;\n\nimport org.springframework.boot.SpringApplication;\nimport org.springframework.boot.autoconfigure.SpringBootApplication;\n\n@SpringBootApplication\npublic class DynamicinsertApplication {\n\n\tpublic static void main(String[] args) {\n\t\tSpringApplication.run(DynamicinsertApplication.class, args);\n\t}\n\n}\n<\/pre>\n<p>The generated <code>DynamicinsertApplicationTests.java<\/code> file.<\/p>\n<p><span style=\"text-decoration: underline\"><em>DynamicinsertApplicationTests.java<\/em><\/span><\/p>\n<pre class=\"brush:java\">package org.jcg.zheng.dynamicinsert;\n\nimport org.junit.jupiter.api.Test;\nimport org.springframework.boot.test.context.SpringBootTest;\n\n@SpringBootTest\nclass DynamicinsertApplicationTests {\n\n\t@Test\n\tvoid contextLoads() {\n\t}\n\n}\n<\/pre>\n<h2 class=\"wp-block-heading\">3. Spring Data DynamicInsert in Entity<\/h2>\n<p>In this step, I will create a <code>DemoEntity.java<\/code> that annotates with <code>@DynamicInsert<\/code>.<\/p>\n<p><span style=\"text-decoration: underline\"><em>DemoEntity.java<\/em><\/span><\/p>\n<pre class=\"brush:java;highlight:[3,14]\">package org.jcg.zheng.dynamicinsert.entity;\n\nimport org.hibernate.annotations.DynamicInsert;\n\nimport jakarta.persistence.Entity;\nimport jakarta.persistence.GeneratedValue;\nimport jakarta.persistence.GenerationType;\nimport jakarta.persistence.Id;\nimport jakarta.persistence.Table;\nimport lombok.Data;\n\n@Entity\n@Table(name = \"T_DEMOTABLE\")\n@DynamicInsert\n@Data\npublic class DemoEntity {\n\n\t@Id\n\t@GeneratedValue(strategy = GenerationType.IDENTITY)\n\tprivate Integer id;\n\n\tprivate String firstName;\n\n\tprivate String lastName;\n\n\tprivate String email;\n\n\tprivate Integer age;\n\n}\n<\/pre>\n<ul class=\"wp-block-list\">\n<li>Line 3: the <code>@DynamicInsert<\/code> is not supported by other JPA providers as it&#8217;s from Hibernate.<\/li>\n<li>Line 14: the <code>@DynamicInsert<\/code> overwrites the default SQL generation. You will see the insert SQL statements generated in <a href=\"#step5\">step 5<\/a>.<\/li>\n<\/ul>\n<h2 class=\"wp-block-heading\">4. Demo Repository<\/h2>\n<p>In this step, I will create a <code>DemoEntityRepo.java<\/code> that extends from <code>org.springframework.data.jpa.repository.JpaRepository<\/code>.<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<p><span style=\"text-decoration: underline\"><em>DemoEntityRepo.java<\/em><\/span><\/p>\n<pre class=\"brush:java\">package org.jcg.zheng.dynamicinsert.repo;\n\nimport org.jcg.zheng.dynamicinsert.entity.DemoEntity;\nimport org.springframework.data.jpa.repository.JpaRepository;\nimport org.springframework.stereotype.Repository;\n\n@Repository\npublic interface DemoEntityRepo extends JpaRepository&lt;DemoEntity, Integer&gt; {\n\n}\n<\/pre>\n<h3 class=\"wp-block-heading\">4.1 DemoEntityRepoTest <\/h3>\n<p>In this step, I will create a <code>DemoEntityRepoTest.java<\/code> that saves the <code>DemoEntity<\/code> with the various <code>null<\/code> fields.  The dynamically generated SQL insert statements will be printed out in <a href=\"#step5\">step 5<\/a>.<\/p>\n<p><span style=\"text-decoration: underline\"><em>DemoEntityRepoTest.java<\/em><\/span><\/p>\n<pre class=\"brush:java;highlight:[20,27,35,36,37,41]\">package org.jcg.zheng.dynamicinsert.repo;\n\nimport org.jcg.zheng.dynamicinsert.entity.DemoEntity;\nimport org.junit.jupiter.api.Test;\nimport org.slf4j.Logger;\nimport org.slf4j.LoggerFactory;\nimport org.springframework.beans.factory.annotation.Autowired;\nimport org.springframework.boot.test.context.SpringBootTest;\n\n@SpringBootTest\nclass DemoEntityRepoTest {\n\n\tprivate static final Logger logger = LoggerFactory.getLogger(DemoEntityRepoTest.class);\n\n\t@Autowired\n\tprivate DemoEntityRepo testRepo;\n\tprivate DemoEntity demoEntity = new DemoEntity();\n\n\t@Test\n\tvoid test_FirstName_only() {\n\t\tdemoEntity.setFirstName(\"Mary\");\n\n\t\tsaveEntity(demoEntity);\n\t}\n\n\t@Test\n\tvoid test_Name_only() {\n\t\tdemoEntity.setFirstName(\"Mary\");\n\t\tdemoEntity.setLastName(\"Zheng\");\n\n\t\tsaveEntity(demoEntity);\n\t}\n\n\tprivate void saveEntity(DemoEntity demoEntity) {\n\t\tlogger.info(\"before save: \" + demoEntity);\n\t\tdemoEntity = testRepo.save(demoEntity);\n\t\tlogger.info(\"after save: \" + demoEntity);\n\t}\n\n\t@Test\n\tvoid test_Name_email() {\n\t\tdemoEntity.setFirstName(\"Mary\");\n\t\tdemoEntity.setLastName(\"Zheng\");\n\t\tdemoEntity.setEmail(\"mary.s.zheng@jcg.org\");\n\n\t\tsaveEntity(demoEntity);\n\t}\n\n}\n<\/pre>\n<ul class=\"wp-block-list\">\n<li>Line 20: <code>test_FirstName_only<\/code> verifies the generated insert SQL statement only including <code>first_name<\/code> and primary key <code>Id<\/code> fields.<\/li>\n<li>Line 27: <code>test_Name_only<\/code> verifies the generated insert SQL statement including both <code>first_name<\/code> and <code>Last_name<\/code> along with the primary key <code>Id<\/code> fields.<\/li>\n<li>Line 35, 36, 37: <code>saveEntity<\/code> method prints the <code>DemoEntity<\/code> data before and after the <code>save<\/code> method.<\/li>\n<li>Lome 41: <code>test_Name_email<\/code> verifies the generated insert SQL statement including <code>first_name<\/code>, <code>last_name<\/code>, and <code>email<\/code> fields.<\/li>\n<\/ul>\n<p>I will configure the <code>application.properties<\/code> to show the SQL statements generated by Hibernate.<\/p>\n<p><span style=\"text-decoration: underline\"><em>application.properties<\/em><\/span><\/p>\n<pre class=\"brush:plain;highlight:[3,4]\">spring.application.name=dynamicinsert\n\nspring.jpa.show-sql=true\nspring.jpa.properties.hibernate.format_sql=true\n<\/pre>\n<ul class=\"wp-block-list\">\n<li>Line 3: enables <code>show-sql<\/code> property.<\/li>\n<li>Line 4: enables <code>format_sql<\/code> property.<\/li>\n<\/ul>\n<h2 class=\"wp-block-heading\"><a name=\"step5\"><\/a>5. Spring Data DynamicInsert Demo<\/h2>\n<p>In this step, I will run the unit tests and capture the console log to verify the insert SQL statements generated by Hibernate.<\/p>\n<p><span style=\"text-decoration: underline\"><em>Junit Output<\/em><\/span><\/p>\n<pre class=\"brush:plain;highlight:[38,40,41,42,43,44,45,46,47,49,50,51,52,53,54,55,56,58,59,60,61,62,63,64]\">11:56:16.914 [main] INFO org.springframework.test.context.support.AnnotationConfigContextLoaderUtils -- Could not detect default configuration classes for test class [org.jcg.zheng.dynamicinsert.repo.DemoEntityRepoTest]: DemoEntityRepoTest does not declare any static, non-private, non-final, nested classes annotated with @Configuration.\n11:56:17.005 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper -- Found @SpringBootConfiguration org.jcg.zheng.dynamicinsert.DynamicinsertApplication for test class org.jcg.zheng.dynamicinsert.repo.DemoEntityRepoTest\n\n  .   ____          _            __ _ _\n \/\\\\ \/ ___'_ __ _ _(_)_ __  __ _ \\ \\ \\ \\\n( ( )\\___ | '_ | '_| | '_ \\\/ _` | \\ \\ \\ \\\n \\\\\/  ___)| |_)| | | | | || (_| |  ) ) ) )\n  '  |____| .__|_| |_|_| |_\\__, | \/ \/ \/ \/\n =========|_|==============|___\/=\/_\/_\/_\/\n\n :: Spring Boot ::                (v3.3.4)\n\n2024-10-12T11:56:17.526-05:00  INFO 22312 --- [dynamicinsert] [           main] o.j.z.d.repo.DemoEntityRepoTest          : Starting DemoEntityRepoTest using Java 17.0.11 with PID 22312 (started by azpm0 in C:\\MaryTools\\workspace\\dynamicinsert)\n2024-10-12T11:56:17.527-05:00  INFO 22312 --- [dynamicinsert] [           main] o.j.z.d.repo.DemoEntityRepoTest          : No active profile set, falling back to 1 default profile: \"default\"\n2024-10-12T11:56:17.903-05:00  INFO 22312 --- [dynamicinsert] [           main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.\n2024-10-12T11:56:17.961-05:00  INFO 22312 --- [dynamicinsert] [           main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 47 ms. Found 1 JPA repository interface.\n2024-10-12T11:56:18.390-05:00  INFO 22312 --- [dynamicinsert] [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...\n2024-10-12T11:56:18.546-05:00  INFO 22312 --- [dynamicinsert] [           main] com.zaxxer.hikari.pool.HikariPool        : HikariPool-1 - Added connection conn0: url=jdbc:h2:mem:75bfbe68-bfaa-4e14-9e50-259e867c0e02 user=SA\n2024-10-12T11:56:18.548-05:00  INFO 22312 --- [dynamicinsert] [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Start completed.\n2024-10-12T11:56:18.602-05:00  INFO 22312 --- [dynamicinsert] [           main] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [name: default]\n2024-10-12T11:56:18.662-05:00  INFO 22312 --- [dynamicinsert] [           main] org.hibernate.Version                    : HHH000412: Hibernate ORM core version 6.5.3.Final\n2024-10-12T11:56:18.703-05:00  INFO 22312 --- [dynamicinsert] [           main] o.h.c.internal.RegionFactoryInitiator    : HHH000026: Second-level cache disabled\n2024-10-12T11:56:19.041-05:00  INFO 22312 --- [dynamicinsert] [           main] o.s.o.j.p.SpringPersistenceUnitInfo      : No LoadTimeWeaver setup: ignoring JPA class transformer\n2024-10-12T11:56:19.871-05:00  INFO 22312 --- [dynamicinsert] [           main] o.h.e.t.j.p.i.JtaPlatformInitiator       : HHH000489: No JTA platform available (set 'hibernate.transaction.jta.platform' to enable JTA platform integration)\nHibernate: \n    drop table if exists t_demotable cascade \nHibernate: \n    create table t_demotable (\n        age integer,\n        id integer generated by default as identity,\n        email varchar(255),\n        first_name varchar(255),\n        last_name varchar(255),\n        primary key (id)\n    )\n2024-10-12T11:56:19.905-05:00  INFO 22312 --- [dynamicinsert] [           main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'\n2024-10-12T11:56:20.262-05:00  INFO 22312 --- [dynamicinsert] [           main] o.j.z.d.repo.DemoEntityRepoTest          : Started DemoEntityRepoTest in 3.042 seconds (process running for 4.069)\n2024-10-12T11:56:20.806-05:00  INFO 22312 --- [dynamicinsert] [           main] o.j.z.d.repo.DemoEntityRepoTest          : before save: DemoEntity(id=null, firstName=Mary, lastName=Zheng, email=null, age=null)\nHibernate: \n    insert \n    into\n        t_demotable\n        (first_name, last_name, id) \n    values\n        (?, ?, default)\n2024-10-12T11:56:20.911-05:00  INFO 22312 --- [dynamicinsert] [           main] o.j.z.d.repo.DemoEntityRepoTest          : after save: DemoEntity(id=1, firstName=Mary, lastName=Zheng, email=null, age=null)\n2024-10-12T11:56:20.924-05:00  INFO 22312 --- [dynamicinsert] [           main] o.j.z.d.repo.DemoEntityRepoTest          : before save: DemoEntity(id=null, firstName=Mary, lastName=null, email=null, age=null)\nHibernate: \n    insert \n    into\n        t_demotable\n        (first_name, id) \n    values\n        (?, default)\n2024-10-12T11:56:20.926-05:00  INFO 22312 --- [dynamicinsert] [           main] o.j.z.d.repo.DemoEntityRepoTest          : after save: DemoEntity(id=2, firstName=Mary, lastName=null, email=null, age=null)\n2024-10-12T11:56:20.930-05:00  INFO 22312 --- [dynamicinsert] [           main] o.j.z.d.repo.DemoEntityRepoTest          : before save: DemoEntity(id=null, firstName=Mary, lastName=Zheng, email=mary.s.zheng@jcg.org, age=null)\nHibernate: \n    insert \n    into\n        t_demotable\n        (email, first_name, last_name, id) \n    values\n        (?, ?, ?, default)\n2024-10-12T11:56:20.932-05:00  INFO 22312 --- [dynamicinsert] [           main] o.j.z.d.repo.DemoEntityRepoTest          : after save: DemoEntity(id=3, firstName=Mary, lastName=Zheng, email=mary.s.zheng@jcg.org, age=null)\n2024-10-12T11:56:20.941-05:00  INFO 22312 --- [dynamicinsert] [ionShutdownHook] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'\nHibernate: \n    drop table if exists t_demotable cascade \n2024-10-12T11:56:20.945-05:00  INFO 22312 --- [dynamicinsert] [ionShutdownHook] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Shutdown initiated...\n2024-10-12T11:56:20.947-05:00  INFO 22312 --- [dynamicinsert] [ionShutdownHook] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Shutdown completed.\n<\/pre>\n<ul class=\"wp-block-list\">\n<li>Line 40-45: the insert SQL statement includes non-null fields: <code>first_name<\/code>, <code>last_name<\/code>, <code>id<\/code>.<\/li>\n<li>Line 49-54: the insert SQL statement includes non-null fields: <code>first_name<\/code>, <code>id<\/code>.<\/li>\n<li>Line 58-63: the insert SQL statement includes non-null fields: <code>email<\/code>, <code>first_name<\/code>, <code>last_name<\/code>, <code>id<\/code>.<\/li>\n<li>Line (38, 46), (47, 55), (56, 64): the <code>DemoEntity's<\/code> data before and after the <code>save<\/code> method.<\/li>\n<\/ul>\n<h2 class=\"wp-block-heading\">6. Conclusion<\/h2>\n<p>As shown in <a href=\"#step5\">step 5<\/a>, the insert SQL statements are different based on the non-null fields, therefore the database can not pre-compile the insert SQL statement&#8217;s execution plan and reuse it for better performance with <code>@DynamicInsert<\/code>. It&#8217;s good to use <code>@DynamicInsert<\/code> when the database table has many columns but the application only inserts data with a few columns.\u00a0It should avoid using <code>@DynamicInsert<\/code> for a batch process due to can not pre-compile the SQL statement.<\/p>\n<h2 class=\"wp-block-heading\">7. Download<\/h2>\n<p>This was an example of a gradle project which included the <code>@DynamicInsert<\/code> annotation.<\/p>\n<div class=\"download\"><strong>Download<\/strong><br \/>\nYou can download the full source code of this example here: <a href=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2024\/10\/dynamicinsert.zip\"><strong>Spring Data JPA Hibernate @DynamicInsert Example<\/strong><\/a><\/div>\n","protected":false},"excerpt":{"rendered":"<p>1. Introduction Spring Data JPA supports common JPA providers, e.g. Hibernate, EclipseLink, etc. Hibernate pre-generates and caches static SQL insert statements that include every mapped column by default. The @org.hibernate.annotations.DynamicInsert overwrites the default implementation and dynamically generates the insert SQL statement for non-null fields at runtime. In this example, I will demonstrate the Spring Data &hellip;<\/p>\n","protected":false},"author":128892,"featured_media":153,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[971,321,2758],"class_list":["post-127379","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-enterprise-java","tag-hibernate","tag-spring-data","tag-spring-jpa"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Spring Data DynamicInsert Annotation Example - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"1. Introduction Spring Data JPA supports common JPA providers, e.g. Hibernate, EclipseLink, etc. Hibernate pre-generates and caches static SQL insert\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.javacodegeeks.com\/spring-data-dynamicinsert-annotation-example.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Spring Data DynamicInsert Annotation Example - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"1. Introduction Spring Data JPA supports common JPA providers, e.g. Hibernate, EclipseLink, etc. Hibernate pre-generates and caches static SQL insert\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.javacodegeeks.com\/spring-data-dynamicinsert-annotation-example.html\" \/>\n<meta property=\"og:site_name\" content=\"Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2024-10-17T14:06:00+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/jboss-hibernate-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Mary Zheng\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Mary Zheng\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/spring-data-dynamicinsert-annotation-example.html#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/spring-data-dynamicinsert-annotation-example.html\"},\"author\":{\"name\":\"Mary Zheng\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/33e795ab61de7fab61ed89b4de1668f5\"},\"headline\":\"Spring Data DynamicInsert Annotation Example\",\"datePublished\":\"2024-10-17T14:06:00+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/spring-data-dynamicinsert-annotation-example.html\"},\"wordCount\":473,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/spring-data-dynamicinsert-annotation-example.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/jboss-hibernate-logo.jpg\",\"keywords\":[\"Hibernate\",\"Spring Data\",\"spring jpa\"],\"articleSection\":[\"Enterprise Java\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/spring-data-dynamicinsert-annotation-example.html#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/spring-data-dynamicinsert-annotation-example.html\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/spring-data-dynamicinsert-annotation-example.html\",\"name\":\"Spring Data DynamicInsert Annotation Example - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/spring-data-dynamicinsert-annotation-example.html#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/spring-data-dynamicinsert-annotation-example.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/jboss-hibernate-logo.jpg\",\"datePublished\":\"2024-10-17T14:06:00+00:00\",\"description\":\"1. Introduction Spring Data JPA supports common JPA providers, e.g. Hibernate, EclipseLink, etc. Hibernate pre-generates and caches static SQL insert\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/spring-data-dynamicinsert-annotation-example.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/spring-data-dynamicinsert-annotation-example.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/spring-data-dynamicinsert-annotation-example.html#primaryimage\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/jboss-hibernate-logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/jboss-hibernate-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/spring-data-dynamicinsert-annotation-example.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Enterprise Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\\\/enterprise-java\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Spring Data DynamicInsert Annotation Example\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Developers Resource Center\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.javacodegeeks.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/javacodegeeks\",\"https:\\\/\\\/x.com\\\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/33e795ab61de7fab61ed89b4de1668f5\",\"name\":\"Mary Zheng\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2024\\\/04\\\/cropped-Mary-Zheng-96x96.jpg\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2024\\\/04\\\/cropped-Mary-Zheng-96x96.jpg\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2024\\\/04\\\/cropped-Mary-Zheng-96x96.jpg\",\"caption\":\"Mary Zheng\"},\"description\":\"Mary graduated from the Mechanical Engineering department at ShangHai JiaoTong University. She also holds a Master degree in Computer Science from Webster University. During her studies she has been involved with a large number of projects ranging from programming and software engineering. She worked as a lead Software Engineer where she led and worked with others to design, implement, and monitor the software solution.\",\"sameAs\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/\"],\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/author\\\/mary-zheng\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Spring Data DynamicInsert Annotation Example - Java Code Geeks","description":"1. Introduction Spring Data JPA supports common JPA providers, e.g. Hibernate, EclipseLink, etc. Hibernate pre-generates and caches static SQL insert","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.javacodegeeks.com\/spring-data-dynamicinsert-annotation-example.html","og_locale":"en_US","og_type":"article","og_title":"Spring Data DynamicInsert Annotation Example - Java Code Geeks","og_description":"1. Introduction Spring Data JPA supports common JPA providers, e.g. Hibernate, EclipseLink, etc. Hibernate pre-generates and caches static SQL insert","og_url":"https:\/\/www.javacodegeeks.com\/spring-data-dynamicinsert-annotation-example.html","og_site_name":"Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2024-10-17T14:06:00+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/jboss-hibernate-logo.jpg","type":"image\/jpeg"}],"author":"Mary Zheng","twitter_card":"summary_large_image","twitter_creator":"@javacodegeeks","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Mary Zheng","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.javacodegeeks.com\/spring-data-dynamicinsert-annotation-example.html#article","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/spring-data-dynamicinsert-annotation-example.html"},"author":{"name":"Mary Zheng","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/33e795ab61de7fab61ed89b4de1668f5"},"headline":"Spring Data DynamicInsert Annotation Example","datePublished":"2024-10-17T14:06:00+00:00","mainEntityOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/spring-data-dynamicinsert-annotation-example.html"},"wordCount":473,"commentCount":0,"publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/spring-data-dynamicinsert-annotation-example.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/jboss-hibernate-logo.jpg","keywords":["Hibernate","Spring Data","spring jpa"],"articleSection":["Enterprise Java"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.javacodegeeks.com\/spring-data-dynamicinsert-annotation-example.html#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.javacodegeeks.com\/spring-data-dynamicinsert-annotation-example.html","url":"https:\/\/www.javacodegeeks.com\/spring-data-dynamicinsert-annotation-example.html","name":"Spring Data DynamicInsert Annotation Example - Java Code Geeks","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/spring-data-dynamicinsert-annotation-example.html#primaryimage"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/spring-data-dynamicinsert-annotation-example.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/jboss-hibernate-logo.jpg","datePublished":"2024-10-17T14:06:00+00:00","description":"1. Introduction Spring Data JPA supports common JPA providers, e.g. Hibernate, EclipseLink, etc. Hibernate pre-generates and caches static SQL insert","breadcrumb":{"@id":"https:\/\/www.javacodegeeks.com\/spring-data-dynamicinsert-annotation-example.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.javacodegeeks.com\/spring-data-dynamicinsert-annotation-example.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/spring-data-dynamicinsert-annotation-example.html#primaryimage","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/jboss-hibernate-logo.jpg","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/jboss-hibernate-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/www.javacodegeeks.com\/spring-data-dynamicinsert-annotation-example.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Java","item":"https:\/\/www.javacodegeeks.com\/category\/java"},{"@type":"ListItem","position":3,"name":"Enterprise Java","item":"https:\/\/www.javacodegeeks.com\/category\/java\/enterprise-java"},{"@type":"ListItem","position":4,"name":"Spring Data DynamicInsert Annotation Example"}]},{"@type":"WebSite","@id":"https:\/\/www.javacodegeeks.com\/#website","url":"https:\/\/www.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Developers Resource Center","publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/33e795ab61de7fab61ed89b4de1668f5","name":"Mary Zheng","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2024\/04\/cropped-Mary-Zheng-96x96.jpg","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2024\/04\/cropped-Mary-Zheng-96x96.jpg","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2024\/04\/cropped-Mary-Zheng-96x96.jpg","caption":"Mary Zheng"},"description":"Mary graduated from the Mechanical Engineering department at ShangHai JiaoTong University. She also holds a Master degree in Computer Science from Webster University. During her studies she has been involved with a large number of projects ranging from programming and software engineering. She worked as a lead Software Engineer where she led and worked with others to design, implement, and monitor the software solution.","sameAs":["https:\/\/www.javacodegeeks.com\/"],"url":"https:\/\/www.javacodegeeks.com\/author\/mary-zheng"}]}},"_links":{"self":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/127379","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/users\/128892"}],"replies":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=127379"}],"version-history":[{"count":0,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/127379\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media\/153"}],"wp:attachment":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=127379"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=127379"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=127379"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}