Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/320.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
出现错误org.hibernate.HibernateException。错误出现在init方法中(以java应用程序的形式运行应用程序时)_Java_Database_Spring_Hibernate_Maven - Fatal编程技术网

出现错误org.hibernate.HibernateException。错误出现在init方法中(以java应用程序的形式运行应用程序时)

出现错误org.hibernate.HibernateException。错误出现在init方法中(以java应用程序的形式运行应用程序时),java,database,spring,hibernate,maven,Java,Database,Spring,Hibernate,Maven,Mvn clean和Mvn安装成功,没有警告和错误。文件hibernate.cfg.xml和App.java为: 初始化期间控制台中的错误为: log4j:WARN No appenders could be found for logger (org.jboss.logging). log4j:WARN Please initialize the log4j system properly. log4j:WARN See http://logging.apache.org/log4j/1.2/

Mvn clean和Mvn安装成功,没有警告和错误。文件hibernate.cfg.xml和App.java为:

初始化期间控制台中的错误为:

log4j:WARN No appenders could be found for logger (org.jboss.logging).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
Exception in thread "main" org.hibernate.HibernateException: Connection cannot be null when 'hibernate.dialect' not set
    at org.hibernate.service.jdbc.dialect.internal.DialectFactoryImpl.determineDialect(DialectFactoryImpl.java:97)
    at org.hibernate.service.jdbc.dialect.internal.DialectFactoryImpl.buildDialect(DialectFactoryImpl.java:67)
    at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:170)
    at org.hibernate.service.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:75)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:159)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:131)
    at org.hibernate.cfg.Configuration.buildTypeRegistrations(Configuration.java:1797)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1755)
    at com.icdab.www.icdab_first.App.init(App.java:33)
    at com.icdab.www.icdab_first.App.main(App.java:76)
Hibernate.cfg.xml:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
<session-factory> 
    <property name="hibernate.connection.driver.class">oracle.jdbc.OracleDriver</property>  
    <property name="hibernate.connection.url">jdbc:oracle:thin:@localhost:1521:ORCL</property>
    <property name="hibernate.connection.username">system</property>
    <property name="hibernate.connection.password">password</property>
    <property name="hiberante.dialect">org.hibernate.dialect.Oracle10gDialect</property>    
    <property name="show_sql">true</property>   
    <mapping class="com.icdab.www.icdab_first.CompundKey" /> 
    <mapping class="com.icdab.www.icdab_first.Customer" />
    <mapping class="com.icdab.www.icdab_first.Employee" />
    <mapping class="com.icdab.www.icdab_first.EventPlan" />
    <mapping class="com.icdab.www.icdab_first.EventPlanLine" />
    <mapping class="com.icdab.www.icdab_first.EventRequest" />
    <mapping class="com.icdab.www.icdab_first.Facility" />
    <mapping class="com.icdab.www.icdab_first.Location" />
    <mapping class="com.icdab.www.icdab_first.ResourceTbl" />

</session-factory>  
</hibernate-configuration>

oracle.jdbc.OracleDriver
jdbc:oracle:thin:@localhost:1521:ORCL
系统
密码
org.hibernate.dialen.oracle10galent
真的
App.java:

package com.icdab.www.icdab_first;

import java.sql.Date;
import java.util.ArrayList;
import java.util.List;
import org.hibernate.Session; 
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration; 
import org.hibernate.service.ServiceRegistry;
import org.hibernate.service.ServiceRegistryBuilder; 
/**
 * Hello world!
 *
 */
public class App 
{
    private SessionFactory factory;
    private void init(){
        System.out.println("in init");
        Configuration config = new Configuration().configure("hibernate.cfg.xml")
                /*.addAnnotatedClass(CompundKey.class)
                .addAnnotatedClass(Customer.class)
                .addAnnotatedClass(Employee.class)
                .addAnnotatedClass(EventPlan.class)
                .addAnnotatedClass(EventPlanLine.class)
                .addAnnotatedClass(EventRequest.class)
                .addAnnotatedClass(Facility.class)
                .addAnnotatedClass(Location.class)
                .addAnnotatedClass(ResourceTbl.class) */;

        // learn why did you use the annotatedclass and configuration.
          ServiceRegistry registry = new ServiceRegistryBuilder().applySettings(config.getProperties()).buildServiceRegistry();
          factory=config.buildSessionFactory(registry);
    }
    @SuppressWarnings("deprecation")
    private void persistAnnotatedLists(){
        Session session = factory.getCurrentSession(); 
        session.beginTransaction();
        Customer customer = new Customer(); 
        customer.setAddress("address123");
        customer.setCity("lansing");
        customer.setContact("1632 ne ave");
        customer.setCustname("john");
        customer.setCustno("1234");
        customer.setInternal("internal");
        customer.setPhone(122345679);
        customer.setState("OR");
        customer.setZip(97654);

        List<EventRequest> ers = new ArrayList<EventRequest>();


        ers.add(new EventRequest(123,new Date(92,5,1),new Date(91,5,1),new Date(93,5,1),"av",123,456,124));
        ers.add(new EventRequest(1234,new Date(92,5,2),new Date(91,5,2),new Date(93,5,2),"av",124,457,125));
        customer.setEventrequests(ers);
        session.save(customer); 

        session.getTransaction().commit();
        System.out.println("done persist");
    }
    private void retrieveList(){
        Session session = factory.getCurrentSession();
        session.beginTransaction(); 

        List list = session.createQuery("from com.icdab.www.icdab_first.Customer").list();

        for (Object object : list) {
            System.out.println("** List items: "+object);
        }
        session.getTransaction().commit();
        System.out.println("Done retrieve");
    }

    public static void main (String[] args){
        App app = new App();
        app.init();
        app.persistAnnotatedLists();
        app.retrieveList();
    }
}
package com.icdab.www.icdab_;
导入java.sql.Date;
导入java.util.ArrayList;
导入java.util.List;
导入org.hibernate.Session;
导入org.hibernate.SessionFactory;
导入org.hibernate.cfg.Configuration;
导入org.hibernate.service.ServiceRegistry;
导入org.hibernate.service.ServiceRegistryBuilder;
/**
*你好,世界!
*
*/
公共类应用程序
{
私营工厂;
私有void init(){
System.out.println(“in init”);
Configuration config=new Configuration().configure(“hibernate.cfg.xml”)
/*.addAnnotatedClass(CompundKey.class)
.addAnnotatedClass(Customer.class)
.addAnnotatedClass(Employee.class)
.addAnnotatedClass(EventPlan.class)
.addAnnotatedClass(EventPlanLine.class)
.addAnnotatedClass(EventRequest.class)
.addAnnotatedClass(Facility.class)
.addAnnotatedClass(Location.class)
.addAnnotatedClass(资源类)*/;
//了解为什么使用annotatedclass和配置。
ServiceRegistry registry=new ServiceRegistryBuilder().applySettings(config.getProperties()).buildServiceRegistry();
factory=config.buildSessionFactory(注册表);
}
@抑制警告(“弃用”)
私有void persistedList(){
Session Session=factory.getCurrentSession();
session.beginTransaction();
客户=新客户();
客户设置地址(“地址123”);
客户。setCity(“兰辛”);
客户。setContact(“东北大街1632号”);
customer.setCustname(“约翰”);
客户。setCustno(“1234”);
客户。setInternal(“内部”);
客户电话(122345679);
客户状态(“或”);
customer.setZip(97654);
List ers=new ArrayList();
添加(新事件请求(123,新日期(92,5,1),新日期(91,5,1),新日期(93,5,1),“av”,123456124);
添加(新事件请求(1234,新日期(92,5,2),新日期(91,5,2),新日期(93,5,2),“av”,124457125);
customer.setEventrequests(ers);
session.save(客户);
session.getTransaction().commit();
System.out.println(“完成”);
}
私有void retrieveList(){
Session Session=factory.getCurrentSession();
session.beginTransaction();
List List=session.createQuery(“from com.icdab.www.icdab_first.Customer”).List();
用于(对象:列表){
System.out.println(“**列表项:“+对象”);
}
session.getTransaction().commit();
System.out.println(“完成检索”);
}
公共静态void main(字符串[]args){
App App=新App();
app.init();
app.persistAnnotatedList();
app.retrieveList();
}
}
项目结构为:


您有一个拼写错误
org.hibernate.dialent.oracle10galent
它应该是
hibernate
,而不是
hibernate
,同时确保您的maven结构保持小写。您应该将“资源”文件夹重命名为“资源”。