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.
Friday, November 23, 2012
Subscribe to:
Comments (Atom)
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 ...
-
As we know that TreeSet by default store the unique value it doesn’t check case of the value that is being added. For example if...
-
We can extract text from pdf file using itext 2.1.6 PdfReader readerN = new PdfReader("pdfFilename"); OutputStream...
-
We mostly use hibernate ‘s sessionFactory.openSession() method which keeps track of all events of hibernate along with managing first ...