<?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="java:hibernate/SessionFactory/MyBlog">
    
    
        <property name="hibernate.show_sql">false</property>
        <property name="hibernate.connection.driver_class">
            com.mysql.jdbc.Driver 
        </property>
        <property name="hibernate.connection.url"> 
            jdbc:mysql://localhost:3306/hibernate_test 
        </property>
        <property name="hibernate.connection.username">
            dbuser
        </property>
        <property name="hibernate.connection.password">
            1234
        </property>
        
        <property name="hibernate.dialect">
            org.hibernate.dialect.MySQLDialect
        </property>
        
        
        <mapping resource="Blog.hbm.xml" /> 
        <mapping resource="BlogItem.hbm.xml" /> 
        
    </session-factory>
    
</hibernate-configuration>两个hbm文件如下:

解决方案 »

  1.   

    <?xml version="1.0"?>
    <!DOCTYPE hibernate-mapping PUBLIC 
            "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
            "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
    <hibernate-mapping>
        
        <class 
            name="BlogItem" 
            table="BLOG_ITEMS" 
            dynamic-update="true">
            
            <id 
                name="id" 
                column="BLOG_ITEM_ID">
                
                <generator class="native"/>
                
            </id>
            
            <property 
                name="title" 
                column="TITLE"
                not-null="true"/>
                
            <property 
                name="text" 
                column="TEXT" 
                not-null="true"/>
                
            <property 
                name="datetime" 
                column="DATE_TIME" 
                not-null="true"/>
                
            <many-to-one 
                name="blog" 
                column="BLOG_ID" 
                not-null="true"/>
                
        </class>
        
    </hibernate-mapping>
    <?xml version="1.0"?>
    <!DOCTYPE hibernate-mapping PUBLIC 
            "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
            "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"><hibernate-mapping>
        <class 
            name="Blog" 
            table="BLOGS" >
            
            <id 
                name="id" 
                column="BLOG_ID">
                
                <generator class="native"/>
                
            </id>
            
            <property 
                name="name" 
                column="NAME" 
                not-null="true" 
                unique="true"/>
                
            <bag 
                name="items" 
                inverse="true" 
                order-by="DATE_TIME" 
                cascade="all">
                
                <key column="BLOG_ID"/>
                <one-to-many class="BlogItem"/>
                
            </bag>
            
        </class>
        
    </hibernate-mapping>
      

  2.   

    public class BlogMain {
        
        private SessionFactory _sessions;    public void exportTables() throws HibernateException {
            Configuration cfg = new Configuration()
                .addClass(Blog.class).addClass(BlogItem.class);
            new SchemaExport(cfg).create(true, true);
        }    public static void main(String[] args){
            BlogMain obj = new BlogMain();
            obj.exportTables();
        }
    结果就出了如题的错误.请问,hibernate3我的配置有何错误?
      

  3.   

    hibernate3Annotation中有个TestCase作测试应该没问题,我看你的SessionFactory 不知道什么时候得到值的?应该是_sessions=cfg.buildSessionFactory
      

  4.   

    用new Configuration().configure().buildSessionFactory()的方式创建SessionFactory。
    用你写的那种方式可能忽略了Hibernate.cfg.xml配置文件,得在程序中调用Configuration.setProperty()来设置属性,
    如 new Configuration().setProperty("hibernate.dialect", "org.hibernate.dialect.MySQLDialect")
      

  5.   

    hugebrush() 说的对,你如果直接用new Configuration()的话,默认的是以hibernate.properties
    文件为默认配置文件,要加doConfigure()这样才是选择hibernate.cfg.xml文件为默认配置文件!