Examples of JPAException


Examples of play.exceptions.JPAException

                                e = e.getCause();
                                if (e == null) {
                                    break;
                                }
                            }
                            throw new JPAException("Cannot commit", e);
                        }
                    }
                }
            }
        } finally {
View Full Code Here

Examples of play.exceptions.JPAException

    public static JPAConfig getJPAConfig(String jpaConfigName, boolean ignoreError) {
        JPAConfig jpaConfig = jpaConfigs.get(jpaConfigName);
        if (jpaConfig==null && !ignoreError) {
            if (!isEnabled()) {
                // Show simpler error message if JPA is not enabled
                throw new JPAException("The JPA context is not initialized. JPA Entity Manager automatically start " +
                        "when one or more classes annotated with the @javax.persistence.Entity annotation " +
                        "are found in the application.");
            } else {
                throw new JPAException("No JPAConfig is found with the name " + jpaConfigName);
            }
        }
        return jpaConfig;
    }
View Full Code Here

Examples of play.exceptions.JPAException

                }
            }
        }

        if (error) {
            throw new JPAException("Error closing one or more transactions");
        }
    }
View Full Code Here

Examples of play.exceptions.JPAException

        }
    }

    private static JPAConfig getDefaultJPAConfig() {
        if (_defaultJPAConfig==null) {
            throw new JPAException("The JPA context is not initialized. JPA Entity Manager automatically start " +
                    "when one or more classes annotated with the @javax.persistence.Entity annotation " +
                    "are found in the application.");
        }
        return _defaultJPAConfig;
    }
View Full Code Here

Examples of play.exceptions.JPAException

                // we're ready to configure this instance of JPA
                final String hibernateDataSource = Play.configuration.getProperty(propPrefix + "hibernate.connection.datasource");

                if (StringUtils.isEmpty(hibernateDataSource) && dbConfig == null) {
                    throw new JPAException("Cannot start a JPA manager without a properly configured database" + getConfigInfoString(configName),
                            new NullPointerException("No datasource configured"));
                }

                Ejb3Configuration cfg = new Ejb3Configuration();

                if (dbConfig.getDatasource() != null) {
                    cfg.setDataSource(dbConfig.getDatasource());
                }

                if (!Play.configuration.getProperty(propPrefix + "jpa.ddl", Play.mode.isDev() ? "update" : "none").equals("none")) {
                    cfg.setProperty("hibernate.hbm2ddl.auto", Play.configuration.getProperty(propPrefix + "jpa.ddl", "update"));
                }

                String driver = null;
                if (StringUtils.isEmpty(propPrefix)) {
                    driver = Play.configuration.getProperty("db.driver");
                } else {
                    driver = Play.configuration.getProperty(propPrefix + "driver");
                }
                cfg.setProperty("hibernate.dialect", getDefaultDialect(propPrefix, driver));
                cfg.setProperty("javax.persistence.transaction", "RESOURCE_LOCAL");


                cfg.setInterceptor(new PlayInterceptor());

                // This setting is global for all JPAs - only configure if configuring default JPA
                if (StringUtils.isEmpty(propPrefix)) {
                    if (Play.configuration.getProperty(propPrefix + "jpa.debugSQL", "false").equals("true")) {
                        org.apache.log4j.Logger.getLogger("org.hibernate.SQL").setLevel(Level.ALL);
                    } else {
                        org.apache.log4j.Logger.getLogger("org.hibernate.SQL").setLevel(Level.OFF);
                    }
                }
                // inject additional  hibernate.* settings declared in Play! configuration
                Properties additionalProperties = (Properties) Utils.Maps.filterMap(Play.configuration, "^" + propPrefix + "hibernate\\..*");
                // We must remove prefix from names
                Properties transformedAdditionalProperties = new Properties();
                for (Map.Entry<Object, Object> entry : additionalProperties.entrySet()) {
                    Object key = entry.getKey();
                    if (!StringUtils.isEmpty(propPrefix)) {
                        key = ((String) key).substring(propPrefix.length()); // chop off the prefix
                    }
                    transformedAdditionalProperties.put(key, entry.getValue());
                }
                cfg.addProperties(transformedAdditionalProperties);


                try {
                    // nice hacking :) I like it..
                    Field field = cfg.getClass().getDeclaredField("overridenClassLoader");
                    field.setAccessible(true);
                    field.set(cfg, Play.classloader);
                } catch (Exception e) {
                    Logger.error(e, "Error trying to override the hibernate classLoader (new hibernate version ???)");
                }

                for (Class<?> clazz : classes) {
                    cfg.addAnnotatedClass(clazz);
                    if (Logger.isTraceEnabled()) {
                        Logger.trace("JPA Model : %s", clazz);
                    }
                }
                String[] moreEntities = Play.configuration.getProperty(propPrefix + "jpa.entities", "").split(", ");
                for (String entity : moreEntities) {
                    if (entity.trim().equals("")) {
                        continue;
                    }
                    try {
                        cfg.addAnnotatedClass(Play.classloader.loadClass(entity));
                    } catch (Exception e) {
                        Logger.warn("JPA -> Entity not found: %s", entity);
                    }
                }

                for (ApplicationClass applicationClass : Play.classes.all()) {
                    if (applicationClass.isClass() || applicationClass.javaPackage == null) {
                        continue;
                    }
                    Package p = applicationClass.javaPackage;
                    Logger.info("JPA -> Adding package: %s", p.getName());
                    cfg.addPackage(p.getName());
                }

                String mappingFile = Play.configuration.getProperty(propPrefix + "jpa.mapping-file", "");
                if (mappingFile != null && mappingFile.length() > 0) {
                    cfg.addResource(mappingFile);
                }

                if (Logger.isTraceEnabled()) {
                    Logger.trace("Initializing JPA" + getConfigInfoString(configName) + " ...");
                }

                try {
                    JPA.addConfiguration(configName, cfg);
                } catch (PersistenceException e) {
                    throw new JPAException(e.getMessage() + getConfigInfoString(configName), e.getCause() != null ? e.getCause() : e);
                }

            }

        }

        // must look for Entity-objects referring to none-existing JPAConfig
        List<Class> allEntityClasses = Play.classloader.getAnnotatedClasses(Entity.class);
        for (Class clazz : allEntityClasses) {
            String configName = Entity2JPAConfigResolver.getJPAConfigNameForEntityClass(clazz);
            if (JPA.getJPAConfig(configName, true) == null) {
                throw new JPAException("Found Entity-class (" + clazz.getName() + ") referring to none-existing JPAConfig" + getConfigInfoString(configName) + ". " +
                        "Is JPA properly configured?");
            }
        }
    }
View Full Code Here

Examples of play.exceptions.JPAException

            // we must initialize it

            if(Invoker.InvocationContext.current().getAnnotation(NoTransaction.class) != null ) {
                //Called method or class is annotated with @NoTransaction telling us that
                //we should not start a transaction
                throw new JPAException("Cannot create JPAContext due to @NoTransaction");
            }

            boolean readOnly = false;
            if (manualReadOnly!=null) {
                readOnly = manualReadOnly;
View Full Code Here

Examples of play.exceptions.JPAException

            if(!Modifier.isAbstract(c.getClass().getModifiers())) {
                JPAConfigurationExtension extension = null;
                try {
                    extension = (JPAConfigurationExtension) c.javaClass.newInstance();
                } catch (Throwable t) {
                    throw new JPAException(String.format("Could not instantiate JPAConfigurationExtension '%s'", c.javaClass.getName()), t);
                }
                if(extension.getConfigurationName() == null || extension.getConfigurationName().equals(configName)) {
                    extension.configure(cfg);
                }
            }
View Full Code Here

Examples of play.exceptions.JPAException

                            e = e.getCause();
                            if (e == null) {
                                break;
                            }
                        }
                        throw new JPAException("Cannot commit", e);
                    }
                }
            }
        } finally {
            entityManager.close();
View Full Code Here

Examples of play.exceptions.JPAException

    private static ThreadLocal<NoSql> local = new ThreadLocal<NoSql>();
    private NoSqlEntityManager entityManager;

    static NoSql get() {
        if (local.get() == null) {
            throw new JPAException("The JPA context is not initialized. JPA Entity Manager automatically start when one or more classes annotated with the @NoSqlEntity annotation are found in the application.");
        }
        return local.get();
    }
View Full Code Here

Examples of yalp.exceptions.JPAException

    boolean readonly = true;
    boolean autoCommit = false;

    static JPA get() {
        if (local.get() == null) {
            throw new JPAException("The JPA context is not initialized. JPA Entity Manager automatically start when one or more classes annotated with the @javax.persistence.Entity annotation are found in the application.");
        }
        return local.get();
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.