3
respostas

Estou criando o projeto com banco oracle ,porem ele esta lançando a seguinte exception e nao craia as tabelas.

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class br.com.casadocodigo.loja.conf.JPAConfiguration: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean br.com.casadocodigo.loja.conf.JPAConfiguration.entityManagerFactory()] threw exception; nested exception is java.lang.IllegalStateException: Could not load JDBC driver class [oracle.jdbc.driver.OracleDriver]

Classes

package br.com.casadocodigo.loja.conf;

import java.util.Properties;

import javax.persistence.EntityManagerFactory;

import org.springframework.context.annotation.Bean; import org.springframework.jdbc.datasource.DriverManagerDataSource; import org.springframework.orm.jpa.JpaTransactionManager; import org.springframework.orm.jpa.JpaVendorAdapter; import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter; import org.springframework.transaction.annotation.EnableTransactionManagement;

@EnableTransactionManagement public class JPAConfiguration {

@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {

    LocalContainerEntityManagerFactoryBean factoryBean = new LocalContainerEntityManagerFactoryBean();

    JpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
    factoryBean.setJpaVendorAdapter(vendorAdapter);

    DriverManagerDataSource dataSource = new DriverManagerDataSource();
    dataSource.setUsername("system");
    dataSource.setPassword("bancooracle");
    dataSource.setUrl("jdbc:oracle:thin:@localhost:1521:xe");
    dataSource.setDriverClassName("oracle.jdbc.driver.OracleDriver");
    factoryBean.setDataSource(dataSource);

    Properties properties = new Properties();
    properties.setProperty("hibernate.dialect", "org.hibernate.dialect.Oracle12cDialect");
    properties.setProperty("hibernate.show_sql", "true");
    properties.setProperty("hibernate.hbm2ddl.auto", "update");

    factoryBean.setJpaProperties(properties);
    factoryBean.setPackagesToScan("br.com.casadocodigo.loja.models");

    return factoryBean;
}

@Bean
public JpaTransactionManager transactionManager(EntityManagerFactory emf) {
    return new JpaTransactionManager(emf);
}

}

@Override protected Class<?>[] getServletConfigClasses() { return new Class[] {AppWebConfiguration.class, JPAConfiguration.class};

}

package br.com.casadocodigo.loja.models;

import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.SequenceGenerator; import javax.persistence.Table;

@Entity @Table(name = "T_CS_PRODUTO") @SequenceGenerator(name = "produto" ,sequenceName = "T_SQ_PRODUTO" ,allocationSize = 1) public class Produto {

@Id 
@GeneratedValue(generator = "produto" ,strategy = GenerationType.SEQUENCE)
@Column(name = "cd_produto")
private int id;
@Column(name = "nm_produto" ,nullable = false)
private String titulo;
@Column(name = "ds_produto")
private String descricao;
@Column(name = "nr_paginas")
private int paginas;

public String getTitulo() {
    return titulo;
}
public void setTitulo(String titulo) {
    this.titulo = titulo;
}
public String getDescricao() {
    return descricao;
}
public void setDescricao(String descricao) {
    this.descricao = descricao;
}
public int getPaginas() {
    return paginas;
}
public void setPaginas(int paginas) {
    this.paginas = paginas;
}

@Override
public String toString() {
    return "Produto [titulo=" + titulo + ", descricao=" + descricao + ", paginas=" + paginas + "]";
}

}

E TAMBEM TENHO O DRIVER ORACLE NO MEU POM.ALGUEM ME AJUDA?

3 respostas

Posta seu pom.xml, por favor

Otavio segue: Já esta com Driver Oracle

4.0.0 org.casadocodigo casadocodigo 1.0.0-SNAPSHOT war casadocodigo org.springframework spring-webmvc 4.1.0.RELEASE org.apache.tomcat tomcat-servlet-api 7.0.30 provided javax.servlet.jsp jsp-api 2.1 provided javax.servlet.jsp.jstl jstl-api 1.2 javax.servlet servlet-api org.glassfish.web jstl-impl 1.2 javax.servlet servlet-api
<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-api</artifactId>
    <version>1.6.1</version>
</dependency>
<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>jcl-over-slf4j</artifactId>
    <version>1.6.1</version>
    <scope>runtime</scope>
</dependency>
<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-log4j12</artifactId>
    <version>1.6.1</version>
    <scope>runtime</scope>
</dependency>
<dependency>
    <groupId>log4j</groupId>
    <artifactId>log4j</artifactId>
    <version>1.2.16</version>
    <scope>runtime</scope>
</dependency>
<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-entitymanager</artifactId>
    <version>4.3.0.Final</version>
</dependency>
<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-core</artifactId>
    <version>4.3.0.Final</version>
</dependency>
<dependency>
    <groupId>org.hibernate.javax.persistence</groupId>
    <artifactId>hibernate-jpa-2.1-api</artifactId>
    <version>1.0.0.Final</version>
</dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-orm</artifactId>
    <version>4.1.0.RELEASE</version>
</dependency>


<dependency> 
        <groupId>oracle</groupId>
        <artifactId>jdbc-driver</artifactId>
        <version>12</version>
        <scope>system</scope> 
        <systemPath>C:/ojdbc8.jar</systemPath>
    </dependency>
false 1.8 1.8 UTF-8

Wqueiroz, Boa Tarde.

Você criou a database? Ele cria as tabelas mas não cria o banco.