数据库有一个错误组织。冬眠冬眠异常。错误出现在init方法中(以java应用程序的形式运行应用程序时)
Mvn清理和Mvn安装成功,没有警告和错误。文件休眠。cfg。xml和应用程序。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)
冬眠。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>
应用程序。爪哇:
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();
}
}
项目结构为:
共 (0) 个答案