/**
 * Copyright (c) 2012, The National Archives <pronom@nationalarchives.gsi.gov.uk>
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following
 * conditions are met:
 *
 *  * Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *
 *  * Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 *  * Neither the name of the The National Archives nor the
 *    names of its contributors may be used to endorse or promote products
 *    derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
package uk.gov.nationalarchives.droid.profile.referencedata;


import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 * @author Alok Kumar Dash
 * 
 */


public class ReferenceDataDaoImpl implements ReferenceDataDao {

    //@PersistenceContext
    //private EntityManager entityManager;

    /**
     * {@inheritDoc}
     */
    @SuppressWarnings("unchecked")
    @Override
    public List<Format> getFormats() {
        Query q = null;
        List<Format> formats = null;

        String query = "from Format order by name";
        //q = entityManager.createQuery(query);

        //formats = q.getResultList();

        return formats;
    }

}

@@ -1725,24 +1725,322 @@
 edata;%0D%0A%0D%0A%0D%0A
+import org.apache.commons.logging.Log;%0D%0Aimport org.apache.commons.logging.LogFactory;%0D%0Aimport uk.gov.nationalarchives.droid.profile.SqlUtils;%0D%0A%0D%0Aimport java.sql.Connection;%0D%0Aimport java.sql.PreparedStatement;%0D%0Aimport java.sql.ResultSet;%0D%0Aimport java.sql.SQLException;%0D%0Aimport java.util.ArrayList;%0D%0A
 import java.
@@ -2172,16 +2172,46 @@
 .Query;%0D
+%0Aimport javax.sql.DataSource;%0D
 %0A%0D%0A/**%0D%0A
@@ -2327,45 +2327,84 @@
     
-//@PersistenceContext
+private static String SELECT_FORMATS = %22SELECT * FROM FORMAT%22;
 %0D%0A    
-//
 private 
 Enti
@@ -2403,35 +2403,89 @@
 ate 
-EntityManager entityManager
+final Log log = LogFactory.getLog(getClass());%0D%0A    private DataSource datasource
 ;%0D%0A%0D
@@ -2529,44 +2529,8 @@
 */%0D%0A
-    @SuppressWarnings(%22unchecked%22)%0D%0A
     
@@ -2592,63 +2592,114 @@
     
-Query q = null;%0D%0A        List%3CFormat%3E formats = null;%0D%0A
+final List%3CFormat%3E formats = new ArrayList%3CFormat%3E(2000); // about 1500 formats as of 2015.%0D%0A        try %7B
 %0D%0A  
@@ -2708,168 +2708,964 @@
     
+ 
-String query = %22from Format order by name%22;%0D%0A        //q = entityManager.createQuery(query);%0D%0A%0D%0A        //formats = q.getResultList();%0D%0A%0D%0A        return formats
+   final Connection conn = datasource.getConnection();%0D%0A            try %7B%0D%0A                final PreparedStatement loadFormat = conn.prepareStatement(SELECT_FORMATS);%0D%0A                try %7B%0D%0A                    final ResultSet results = loadFormat.executeQuery();%0D%0A                    try %7B%0D%0A                        while (results.next()) %7B%0D%0A                            formats.add(SqlUtils.buildFormat(results));%0D%0A                        %7D%0D%0A                    %7D finally %7B%0D%0A                        results.close();%0D%0A                    %7D%0D%0A                %7D finally %7B%0D%0A                    loadFormat.close();%0D%0A                %7D%0D%0A            %7D finally%7B%0D%0A                conn.close();%0D%0A            %7D%0D%0A        %7D catch (SQLException e) %7B%0D%0A            log.error(%22A database exception occurred getting all formats.%22, e);%0D%0A        %7D%0D%0A        return formats;%0D%0A%0D%0A    %7D%0D%0A%0D%0A    public void setDatasource(DataSource datasource) %7B%0D%0A        this.datasource = datasource
 ;%0D%0A 

Use JDBC rather than hibernate to get the list of formats.