Friday, November 23, 2012

ResultTransformer in Hibernate

Retrieving a non managed entity from database using hibrnate.

If an entity is not mapped to the configuration file and we try to retrieve it from the database generatlly it throws mapping exception.

To get ride of such a situation we can user ResultTranform to retrieve the datafrom the database and map it to a bean which is not an entity or mapped in configuration.

Cautions:Attributes name and datatype in bean and the database should be same.

See the below the snap of code to implement ResultTransformer.

            Session session=Connector.getSession();
            Transaction tx=session.beginTransaction();
                  
           Query query=session.createSQLQuery("SELECT * FROM customer");
           
           List<Customer> list= query.setResultTransformer(Transformers.aliasToBean(Customer.class)).list()
;
    
     Note: Customer is a non mapped entity it is simple a java bean.

Spring Boot Config Server and Config Client.

 In Spring cloud config we can externalise our configuration files to some repository like GIT HUT, Amazon S3 etc. Benefit of externalising ...