写的hibernate.cfg.xml文件如下:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"
http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory name="test">
<property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="connection.password">ix36</property>
<property name="connection.url">jdbc:oracle:thin:@localhost:1521:orcl</property>
<property name="connection.username">ix36</property>
<property name="default_schema">ix36</property>
<property name="dialect">org.hibernate.dialect.Oracle10gDialect</property>
<property name="show_sql">true</property>
<mapping resource="test"/>
</session-factory>
</hibernate-configuration>
相应的调用类如下:
public static void main(String[] args) {
// TODO Auto-generated method stub
try{
Configuration cfg=new Configuration();
SchemaExport export = new SchemaExport(cfg);
export.create(true, true);
}catch(HibernateException e){
e.printStackTrace();
}
}
但是运行后出现错误信息如下:
log4j:WARN No appenders could be found for logger (org.hibernate.type.BasicTypeRegistry).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See
http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
org.hibernate.HibernateException: The dialect was not set. Set the property hibernate.dialect.
at org.hibernate.dialect.Dialect.instantiateDialect(Dialect.java:191)
at org.hibernate.dialect.Dialect.getDialect(Dialect.java:169)
at org.hibernate.dialect.Dialect.getDialect(Dialect.java:184)
at org.hibernate.tool.hbm2ddl.SchemaExport.<init>(SchemaExport.java:123)
at org.hibernate.tool.hbm2ddl.SchemaExport.<init>(SchemaExport.java:92)
at testBook.DoFirst.main(DoFirst.java:16)
想让大家帮忙看看是不是哪里配错了,还是少什么包,谢谢了。
配置没有物誉滑问题。关键在代码。
Configuration cfg=new Configuration(); // 默认为"/hibernate.cfg.xml", 在WEB应用下没问题,java应用程序中八成是找不到的,要指定配罩腊置文件路径。
cfg.configure("hibernate.cfg.xml"); //虚漏 指定配置文件路径
SchemaExport export = new SchemaExport(cfg);
你的oracle方言配置的拆姿不对 和oracle的版本不匹配
<property name="dialect">org.hibernate.dialect.Oracle10gDialect</property>
或告昌者旅友绝可以在eclipse下测试连接是否成功,他有视图测试 直接按步骤测试