Example usage for org.hibernate Session createNativeQuery

List of usage examples for org.hibernate Session createNativeQuery

Introduction

In this page you can find the example usage for org.hibernate Session createNativeQuery.

Prototype

NativeQuery createNativeQuery(String sqlString);

Source Link

Document

Create a NativeQuery instance for the given native (SQL) query

Usage

From source file:org.mycore.frontend.cli.MCRClassification2Commands.java

License:Open Source License

private static void checkMissingParent(String classID, List<String> log) {
    Session session = MCRHIBConnection.instance().getSession();
    String sqlQuery = "select cat.categid from {h-schema}MCRCategory cat WHERE cat.classid='" + classID
            + "' and cat.level > 0 and cat.parentID is NULL";
    @SuppressWarnings("unchecked")
    List<String> list = session.createNativeQuery(sqlQuery).getResultList();

    for (String categIDString : list) {
        log.add("parentID is null for category " + new MCRCategoryID(classID, categIDString));
    }/*from w  ww .jav a 2s .c om*/
}

From source file:org.mycore.frontend.cli.MCRClassification2Commands.java

License:Open Source License

@MCRCommand(syntax = "repair missing parent for classification {0}", help = "restores parentID from information in the given classification, if left right values are correct", order = 130)
public static void repairMissingParent(String classID) {
    Session session = MCRHIBConnection.instance().getSession();
    String sqlQuery = "update {h-schema}MCRCategory cat set cat.parentID=(select parent.internalID from {h-schema}MCRCategory parent WHERE parent.classid='"
            + classID//ww w.  j ava 2  s .c om
            + "' and parent.leftValue<cat.leftValue and parent.rightValue>cat.rightValue and parent.level=(cat.level-1)) WHERE cat.classid='"
            + classID + "' and cat.level > 0 and cat.parentID is NULL";
    int updates = session.createNativeQuery(sqlQuery).executeUpdate();
    LOGGER.info(() -> "Repaired " + updates + " parentID columns for classification " + classID);
}

From source file:org.openflexo.jdbc.test.JDBCTestCase.java

License:Open Source License

public void debugTable(Session session, String entityName) {
    NativeQuery<?> sqlQ = session.createNativeQuery("select * from " + entityName + ";");
    System.out.println("select * from " + entityName + ";");
    for (Object rowResult : sqlQ.getResultList()) {
        if (rowResult.getClass().isArray()) {
            StringBuffer sb = new StringBuffer();
            for (Object o : (Object[]) rowResult) {
                sb.append(" " + o);
            }/*from  w  w  w . j  a  v a 2  s.co  m*/
            System.out.println(" > " + sb.toString());
        }
    }
}