Uploaded image for project: 'Ignite'
  1. Ignite
  2. IGNITE-8516

Not null constraint doesn't checked

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 2.4
    • 2.7
    • sql
    • None

    Description

      User is able to insert null into the not null column through cache-api.
      If one uncomment line entries.put(new Organization("2"), new Address("Some address")); - constraint applied and exception would be thrown.
      The same behaviour is expected for the 1 entry map.

      Reproducer:

      package org.apache.ignite.internal.processors.sql;
      
      public class IgniteNotNullBug extends GridCommonAbstractTest {
          @Override protected void beforeTestsStarted() throws Exception {
              startGrid(0);
      
              Set<String> nn = new HashSet<>();
              nn.add("address");
      
              jcache(grid(0), cacheConfiguration(new QueryEntity(Organization.class.getName(), Address.class.getName())
                  .addQueryField("address", "java.lang.String", "address")
                  .setNotNullFields(nn)), "ORG_ADDRESS");
          }
      
          public void testPutNullField() throws Exception {
              Map<Organization, Address> entries = new HashMap<>();
      
              entries.put(new Organization("1"), new Address(null));
              //entries.put(new Organization("2"), new Address("Some address"));
      
              IgniteCache<Organization, Address> cache = jcache(0, "ORG_ADDRESS");
      
              cache.putAll(entries);
      
              System.out.println("cache.getConfiguration(CacheConfiguration) = " + cache.getConfiguration(CacheConfiguration.class).getQueryEntities());
      
              List<?> objects = execSql("SELECT address FROM ORG_ADDRESS.ADDRESS");
              
              assert ((List)objects.get(0)).get(0) == null;
          }
      
          protected CacheConfiguration cacheConfiguration(QueryEntity qryEntity) {
              CacheConfiguration<?, ?> cache = defaultCacheConfiguration();
      
              cache.setCacheMode(CacheMode.PARTITIONED);
              cache.setAtomicityMode(CacheAtomicityMode.ATOMIC);
              cache.setBackups(1);
              cache.setWriteSynchronizationMode(FULL_SYNC);
      
              cache.setQueryEntities(Collections.singletonList(qryEntity));
      
              return cache;
          }
      
          private List<?> execSql(String sql, Object... args) {
              SqlFieldsQuery qry = new SqlFieldsQuery(sql)
                  .setArgs(args);
      
              return grid(0).context().query().querySqlFields(qry, true).getAll();
          }
      
          private static class Organization implements Serializable {
              private final String name;
              private Organization(String name) { this.name = name; }
          }
      
          private static class Address implements Serializable {
              private final String address;
              private Address(String address) { this.address = address; }
          }
      }
      

      Attachments

        Issue Links

          Activity

            People

              garus.d.g Denis Garus
              nizhikov Nikolay Izhikov
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: