Create Java EE 7 Algaworks Workbook

Asked

Viewed 100 times

0

I’m trying to create the Java EE 7 course database with Jsf, Primefaces and CDI and I’m not getting it.
Make the mistake below:

set 17, 2017 8:24:22 PM org.hibernate.annotations.common.Version <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {4.0.2.Final}
set 17, 2017 8:24:22 PM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {4.2.3.Final}
set 17, 2017 8:24:22 PM org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
set 17, 2017 8:24:22 PM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
set 17, 2017 8:24:23 PM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000402: Using Hibernate built-in connection pool (not for production use!)
set 17, 2017 8:24:23 PM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000115: Hibernate connection pool size: 20
set 17, 2017 8:24:23 PM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000006: Autocommit mode: true
set 17, 2017 8:24:23 PM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000401: using driver [com.mysql.jdbc.Driver] at URL [jdbc:mysql://localhost/financeiro]
set 17, 2017 8:24:23 PM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000046: Connection properties: {user=root, autocommit=true, release_mode=auto}
set 17, 2017 8:24:23 PM org.hibernate.engine.jdbc.internal.JdbcServicesImpl configure
WARN: HHH000342: Could not obtain connection to query metadata : Base 'financeiro' inconnue
set 17, 2017 8:24:23 PM org.hibernate.dialect.Dialect <init>
INFO: HHH000400: Using dialect: org.hibernate.dialect.MySQL5Dialect
set 17, 2017 8:24:23 PM org.hibernate.engine.jdbc.internal.LobCreatorBuilder useContextualLobCreation
INFO: HHH000422: Disabling contextual LOB creation as connection was null
set 17, 2017 8:24:23 PM org.hibernate.engine.transaction.internal.TransactionFactoryInitiator initiateService
INFO: HHH000268: Transaction strategy: org.hibernate.engine.transaction.internal.jdbc.JdbcTransactionFactory
set 17, 2017 8:24:23 PM org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory <init>
INFO: HHH000397: Using ASTQueryTranslatorFactory
set 17, 2017 8:24:23 PM org.hibernate.tool.hbm2ddl.SchemaExport execute
INFO: HHH000227: Running hbm2ddl schema export
set 17, 2017 8:24:23 PM org.hibernate.tool.hbm2ddl.SchemaExport execute
ERROR: HHH000231: Schema export unsuccessful
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Base 'financeiro' inconnue
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:377)
    at com.mysql.jdbc.Util.getInstance(Util.java:360)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:978)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3887)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3823)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:870)
    at com.mysql.jdbc.MysqlIO.proceedHandshakeWithPluggableAuthentication(MysqlIO.java:1659)
    at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1206)
    at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2234)
    at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2265)
    at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2064)
    at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:790)
    at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:44)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:377)
    at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:395)
    at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:325)
    at org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl.getConnection(DriverManagerConnectionProviderImpl.java:204)
    at org.hibernate.tool.hbm2ddl.SuppliedConnectionProviderConnectionHelper.prepare(SuppliedConnectionProviderConnectionHelper.java:51)
    at org.hibernate.tool.hbm2ddl.DatabaseExporter.<init>(DatabaseExporter.java:52)
    at org.hibernate.tool.hbm2ddl.SchemaExport.execute(SchemaExport.java:367)
    at org.hibernate.tool.hbm2ddl.SchemaExport.create(SchemaExport.java:304)
    at org.hibernate.tool.hbm2ddl.SchemaExport.create(SchemaExport.java:293)
    at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:500)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1769)
    at org.hibernate.ejb.EntityManagerFactoryImpl.<init>(EntityManagerFactoryImpl.java:96)
    at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:914)
    at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:899)
    at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:59)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:63)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:47)
    at com.algaworks.financeiro.util.CriaTabelas.main(CriaTabelas.java:7)

set 17, 2017 8:24:23 PM org.hibernate.tool.hbm2ddl.SchemaExport execute
INFO: HHH000230: Schema export complete

My persintence.xml

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0"
xmlns="http://java.sun.com/xml/ns/persistence" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence 
    http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">

<persistence-unit name="FinanceiroPU">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <properties>
        <property name="javax.persistence.jdbc.url"
            value="jdbc:mysql://localhost/financeiro"/>
        <property name="javax.persistence.jdbc.user"
            value="root" />
        <property name="javax.persistence.jdbc.password"
            value="" />
        <property name="javax.persistence.jdbc.driver"
            value="com.mysql.jdbc.Driver" />
        <property name="hibernate.dialect"
            value="org.hibernate.dialect.MySQL5Dialect" />
        <property name="hibernate.show_sql" value="true" />
        <property name="hibernate.format_sql" value="true" />

My class Criatables

package com.algaworks.financeiro.util;

import javax.persistence.Persistence;

public class CriaTabelas {
public static void main(String[] args) {
    Persistence.createEntityManagerFactory("FinanceiroPU");
    }
}
  • There are users who think that other Stackoverflow users have telepathic magical powers of clairvoyance and are able to guess exactly what is happening in the environment of those who ask. They believe that these superpowered Stackoverflownian beings can guess what the code is, the error message, the system configuration and all other necessary information without needing to see anything about it and are still able to find out what’s wrong with it all. https://pt.meta.stackoverflow.com/questions/5483/manual-de-como-nÃo-fazer-perguntas/5484#5484

  • Check if you have this database created and if the name is the same as you put in persistence.xml.

  • A question, your Mysql is running on which port?

1 answer

0

There is a connection problem with the base financeiro. To try to solve this problem, follow the steps below:

  1. Check the connection data passed by parameter. I noticed that you passed the password as blank. If you really don’t have a password, put one in and test it again. Preferably do a connection test using Mysql Workbench
  2. Remove the properties: hibernate.dialect, hibernate.show_sql, hibernate.format_sql they are optional
  3. Add the property: javax.persistence.schema-generation.create-source
  4. Re-download the Maven dependencies

Below I put a persistence.xml configuration that works normally:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1"
    xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
    <persistence-unit name="crudPU">

        <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>

        <properties>
            <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost/crude-tarefa" />
            <property name="javax.persistence.jdbc.user" value="root" />
            <property name="javax.persistence.jdbc.password" value="root" />
            <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
            <property name="javax.persistence.schema-generation.create-source" value="metadata" /> 
        </properties>

    </persistence-unit> 
</persistence>

Follow all these steps and you should be able to make the connection.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.