Home > Enterprise >  how configure code manual for spring.jackson.deserialization.wrap-exceptions= false not in applicati
how configure code manual for spring.jackson.deserialization.wrap-exceptions= false not in applicati

Time:06-18

Im using HQL- hibernate Query Languange. The reason for spring.jackson.deserialization.wrap-exceptions= false will disregard the exception because i already have customize RuntimeException .

Reason for now working: I have docker and this must also configure in HibernateUtil.

This was working until we change to HQL. In Configuration in Environment has no config for spring.jackson.deserialization.wrap-exceptions= false.

Trying to do: Instead using spring.jackson.deserialization.wrap-exceptions= false in application.yaml. what i think is manual code it but i dont know how.

Hibernate configuration



import java.util.Properties;

import com.product.Entity.Product;

import org.hibernate.SessionFactory;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment;
import org.hibernate.service.ServiceRegistry;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;





@Component
public class HibernateUtil {
    
    
    private static  HibernateUtilModel hibernateUtilModel;
    
    private static SessionFactory sessionFactory;
    
    
    @Autowired
    public void autowairedFixStatic(HibernateUtilModel hibernateUtilModel){
        HibernateUtil.hibernateUtilModel= hibernateUtilModel;
    }
    
    public static SessionFactory getSessionFactory() {
        
        
        if (sessionFactory == null) {
            try {
                Configuration configuration = new Configuration();

                Properties settings = new Properties();
                settings.put(Environment.DRIVER, hibernateUtilModel.getDriver());
                settings.put(Environment.URL, hibernateUtilModel.getUrl());
                settings.put(Environment.USER, hibernateUtilModel.getUser());
                settings.put(Environment.PASS, hibernateUtilModel.getPass());
                settings.put(Environment.DIALECT, hibernateUtilModel.getDialect());

                settings.put(Environment.SHOW_SQL, hibernateUtilModel.getShow_sql());
                settings.put(Environment.IMPLICIT_NAMING_STRATEGY,hibernateUtilModel.getIMPLICIT());
                settings.put(Environment.PHYSICAL_NAMING_STRATEGY,hibernateUtilModel.getPHYSICAL());
                
                settings.put(Environment.CURRENT_SESSION_CONTEXT_CLASS, "thread");

                settings.put(Environment.HBM2DDL_AUTO, hibernateUtilModel.getUpdate());

                configuration.setProperties(settings);

                configuration.addAnnotatedClass(Product.class);

                ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder()
                    .applySettings(configuration.getProperties()).build();

                sessionFactory = configuration.buildSessionFactory(serviceRegistry);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return sessionFactory;
    }
    


}

#Application.yaml

spring:
  jackson:
    deserialization:
      wrap-exceptions: false



import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.Getter;
import lombok.NoArgsConstructor;


@Data
@AllArgsConstructor
@NoArgsConstructor
@Service
public class HibernateUtilModel {
    
    
    @Value("${spring.datasource.url}")
    private  String url;
    
    @Value("${spring.datasource.driver-class-name}")
    private String driver;
    
    @Value("${spring.datasource.username}")
    private  String user;
    
    @Value("${spring.datasource.password}")
    private String pass;
    
    @Value("${spring.jpa.properties.hibernate.dialect}")
    private  String dialect;
    
    @Value("${spring.jpa.show-sql}")
    private String show_sql;
    
    @Value("${spring.jpa.hibernate.naming.implicit-strategy}")
    private String IMPLICIT;
    
    @Value("${spring.jpa.hibernate.naming.physical-strategy}")
    private  String PHYSICAL;
    
    @Value("${spring.jpa.hibernate.ddl-auto}")
    private  String update;
    
    @Value("${spring.jackson.deserialization.wrap-exceptions}")
    private String errorWrapper;

    

}

CodePudding user response:

Since spring.jackson.deserialization.wrap-exceptions= false wont work even using objectmapper. I trace that issue by this post question of mine but i dont know if its advisable to use it.

HttpMessageNotReadableException removing json error message

  • Related