How to make null must error if input is empty in mybatis?

339 views Asked by At

Im trying to insert empty data and it must error but its still saving. I try try/cath and if statement if null and still not working. Can anyone suggest how to do it?

Output in this image RPCbloom

This project is Spring-boot with GRPC and MyBatis.

package com.cartservice.Repository;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.cartservice.Model.Client;
import com.cartservice.Model.ProductEntity;
import com.grpcserver.product.ProductServer.Product;

@Mapper
public interface ProductDAO {
    
    
    @Insert("INSERT INTO tb_product(purchase_item,  productname, productbrand,productprice,productdescription,productquantity,productexpirationdate) " +
              " VALUES (#{purchase_item}, #{productname}, #{productbrand}, #{productprice}, #{productdescription}, #{productquantity}, #{productexpirationdate} )")
@Options(useGeneratedKeys = true, keyColumn = "purchase_item", keyProperty = "purchase_item")
    public int insert(ProductEntity  productEntity);
    
    
    
     
}

    @Override
    public void insert(Product request, StreamObserver<APIResponse> responseObserver) {

    
    ProductEntity productEntity = new ProductEntity();

    
    productEntity.setPurchase_item(request.getPurchaseItem());
    productEntity.setProductname(request.getProductname());
    productEntity.setProductbrand(request.getProductbrand());
    productEntity.setProductprice(request.getProductprice());
    productEntity.setProductdescription(request.getProductdescription());
    productEntity.setProductquantity(request.getProductquantity());
    productEntity.setProductexpirationdate(dateConvert.getDateFromDateProto(request.getProductexpirationdate()));


    productServiceImpl.saveDataFromDTO(productEntity);
    APIResponse.Builder  responce = APIResponse.newBuilder();
    responce.setResponseCode(0).setResponsemessage("Succefull added to database " +productEntity);
    
    responseObserver.onNext(responce.build());
    responseObserver.onCompleted(); 
        
    
    
        
    }

1

There are 1 answers

0
SpicySandwich On

fix i use GRPC "hasField"

for more Handling null values in protobuffers