diff --git a/.settings/org.eclipse.m2e.core.prefs b/.settings/org.eclipse.m2e.core.prefs index f5d84e9d5bfeccbc7efdea90e30fb34f468c53b0..f897a7f1cb2389f85fe6381425d29f0a9866fb65 100644 --- a/.settings/org.eclipse.m2e.core.prefs +++ b/.settings/org.eclipse.m2e.core.prefs @@ -1,4 +1,4 @@ -activeProfiles=D\:\\JavaIDE\\apache-maven-3.6.3/ +activeProfiles= eclipse.preferences.version=1 -resolveWorkspaceProjects=false +resolveWorkspaceProjects=true version=1 diff --git a/mybatis-jpa-extra-core/src/main/java/org/apache/mybatis/jpa/persistence/provider/SqlProviderInsert.java b/mybatis-jpa-extra-core/src/main/java/org/apache/mybatis/jpa/persistence/provider/SqlProviderInsert.java index 96a7b902c1ba7a51118f978bb3afb57dcc09d9a2..3d167c6020ec82220c345cbf60c37f0df07a4d29 100644 --- a/mybatis-jpa-extra-core/src/main/java/org/apache/mybatis/jpa/persistence/provider/SqlProviderInsert.java +++ b/mybatis-jpa-extra-core/src/main/java/org/apache/mybatis/jpa/persistence/provider/SqlProviderInsert.java @@ -33,10 +33,15 @@ public class SqlProviderInsert { sql.INSERT_INTO(MapperMetadata.getTableName(entity.getClass())); for (int i = 0; i < listFields.size(); i++) { FieldColumnMapper fieldColumnMapper=listFields.get(i); - if(fieldColumnMapper.getFieldType().equalsIgnoreCase("String") - &&BeanUtil.getValue(entity, fieldColumnMapper.getFieldName())==null - &&fieldColumnMapper.getGeneratedValue()==null) { + if( + ( + fieldColumnMapper.getFieldType().equalsIgnoreCase("String") + ||fieldColumnMapper.getFieldType().startsWith("byte") + ) + &&BeanUtil.getValue(entity, fieldColumnMapper.getFieldName())==null + &&fieldColumnMapper.getGeneratedValue()==null) { //skip null field value + _logger.trace("skip field value is null "); }else { //have GeneratedValue and (value is null or eq "") if(fieldColumnMapper.getGeneratedValue()!=null diff --git a/mybatis-jpa-extra-core/src/main/java/org/apache/mybatis/jpa/persistence/provider/SqlProviderUpdate.java b/mybatis-jpa-extra-core/src/main/java/org/apache/mybatis/jpa/persistence/provider/SqlProviderUpdate.java index 21540542be9f1219c2cdf939d54e5a8fb32ea0e6..ce6f72fce0cf9141677b0c14b3d305ac74d3adcb 100644 --- a/mybatis-jpa-extra-core/src/main/java/org/apache/mybatis/jpa/persistence/provider/SqlProviderUpdate.java +++ b/mybatis-jpa-extra-core/src/main/java/org/apache/mybatis/jpa/persistence/provider/SqlProviderUpdate.java @@ -34,12 +34,19 @@ public class SqlProviderUpdate { for (int i = 0; i < listFields.size(); i++) { FieldColumnMapper fieldColumnMapper=listFields.get(i); + _logger.trace("Field " +fieldColumnMapper.getFieldName()+" , Type "+ fieldColumnMapper.getFieldType()); + if (fieldColumnMapper.isIdColumn()) { continue; } - if(fieldColumnMapper.getFieldType().equalsIgnoreCase("String")&&BeanUtil.getValue(entity, fieldColumnMapper.getFieldName())==null) { + if( + (fieldColumnMapper.getFieldType().equalsIgnoreCase("String") + ||fieldColumnMapper.getFieldType().startsWith("byte") + ) + &&BeanUtil.getValue(entity, fieldColumnMapper.getFieldName())==null) { //skip null field value + _logger.trace("skip field value is null "); }else { sql.SET(fieldColumnMapper.getColumnName() + "=#{" + fieldColumnMapper.getFieldName() + "}"); } diff --git a/mybatis-jpa-extra-core/src/test/java/org/apache/mybatis/jpa/test/MyBatisTestRunner.java b/mybatis-jpa-extra-core/src/test/java/org/apache/mybatis/jpa/test/MyBatisTestRunner.java index bb8d360d4a0793a417ba49afb8314485f0aa7bbe..b961eeb31c05423741e28b7ab08cd4f6b8eae295 100644 --- a/mybatis-jpa-extra-core/src/test/java/org/apache/mybatis/jpa/test/MyBatisTestRunner.java +++ b/mybatis-jpa-extra-core/src/test/java/org/apache/mybatis/jpa/test/MyBatisTestRunner.java @@ -58,7 +58,7 @@ public class MyBatisTestRunner { Thread.sleep(1000); _logger.info("insert id " + student.getId()); - service.remove(student.getId()); + //service.remove(student.getId()); } @@ -71,6 +71,23 @@ public class MyBatisTestRunner { _logger.info("Students "+student); } + @Test + public void update() throws Exception{ + _logger.info("get..."); + Students student=service.get("317d5eda-927c-4871-a916-472a8062df23"); + System.out.println("Students "+student); + _logger.info("Students "+student); + + _logger.info("update..."); + student.setImages(null); + service.update(student); + _logger.info("updateed."); + + student.setImages("ssss".getBytes()); + service.update(student); + _logger.info("updateed2."); + } + @Test public void find() throws Exception{ diff --git a/mybatis-jpa-extra-core/src/test/java/org/apache/mybatis/jpa/test/domain/Students.java b/mybatis-jpa-extra-core/src/test/java/org/apache/mybatis/jpa/test/domain/Students.java index 75cca8af816f665103293f72e6226ca10d0fece6..e06bd0a69dc9da502018490161d2157029e610c0 100644 --- a/mybatis-jpa-extra-core/src/test/java/org/apache/mybatis/jpa/test/domain/Students.java +++ b/mybatis-jpa-extra-core/src/test/java/org/apache/mybatis/jpa/test/domain/Students.java @@ -52,6 +52,9 @@ public class Students extends JpaBaseDomain implements Serializable{ @Column private String stdClass; + @Column + private byte[] images; + public Students() { super(); @@ -131,6 +134,16 @@ public class Students extends JpaBaseDomain implements Serializable{ } + public byte[] getImages() { + return images; + } + + + public void setImages(byte[] images) { + this.images = images; + } + + @Override public String toString() { return "Students [id=" + id + ", stdNo=" + stdNo + ", stdName=" + stdName + ", stdGender=" + stdGender diff --git a/mybatis-jpa-extra-core/src/test/resources/log4j2.xml b/mybatis-jpa-extra-core/src/test/resources/log4j2.xml index 22473d1a590d1f66b5ebfce2d0b011d389b22bbd..a45f96e61d61020e6b600e40f97c7aa05630e6b0 100644 --- a/mybatis-jpa-extra-core/src/test/resources/log4j2.xml +++ b/mybatis-jpa-extra-core/src/test/resources/log4j2.xml @@ -5,18 +5,16 @@ - - - - - - - - - - - - - - + + + + + + + + + + + + \ No newline at end of file diff --git a/mybatis-jpa-extra-test/src/test/resources/log4j2.xml b/mybatis-jpa-extra-test/src/test/resources/log4j2.xml index 22473d1a590d1f66b5ebfce2d0b011d389b22bbd..c38c1b85aea39ebe1bf015d369f7c75038f75bc5 100644 --- a/mybatis-jpa-extra-test/src/test/resources/log4j2.xml +++ b/mybatis-jpa-extra-test/src/test/resources/log4j2.xml @@ -11,12 +11,9 @@ - - - - - - + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml index 60fa0a0b2bda8853793542ce8de39f937a20c082..33e3fa60a9b6e109f69b0710b597e962da68f341 100644 --- a/pom.xml +++ b/pom.xml @@ -35,6 +35,11 @@ + + mvnrepository + mvnrepository + http://mvnrepository.com/ + sonatype-nexus-staging Sonatype Nexus Staging @@ -45,14 +50,6 @@ jcenter http://jcenter.bintray.com - @@ -140,12 +137,12 @@ org.mybatis mybatis - 3.5.3 + 3.5.6 org.mybatis mybatis-spring - 2.0.2 + 2.0.6 com.alibaba