2011-10-27 21 views
0

嗨,我忙於使用Hibernate和Spring開發Java EE應用程序。我有一個我已經運行的文章類。但是沒有爲其生成表格。控制檯中沒有錯誤。該數據庫沒有生成它的表

下面是文章類:

​​

和ArticleDao類:

package com.bd.dao; 

import java.util.Collection; 
import java.util.List; 



import org.hibernate.SessionFactory; 
import org.springframework.beans.factory.annotation.Autowired; 
import org.springframework.context.annotation.Configuration; 
import org.springframework.stereotype.Repository; 
import org.springframework.transaction.annotation.Transactional; 

import com.bd.entity.Article; 
@Repository 
@Transactional 
@Configuration 
public class ArticleDaoImp implements ArticleDao { 

    @Autowired 
    SessionFactory sessionFactory; 

    @SuppressWarnings("unchecked") 
    @Transactional(readOnly = true) 
    public List<Article> getAll() { 

     return sessionFactory.getCurrentSession().createQuery("from Article") 
       .list(); 
    } 

    @Transactional(readOnly = true) 
    public Article getById(int articleId) { 

     return (Article) sessionFactory.getCurrentSession().get(Article.class, 
       articleId); 
    } 

    @Override 
    public void save(Article article) { 
     sessionFactory.getCurrentSession().merge(article); 

    } 

    @Override 
    public void delete(Article article) { 
     sessionFactory.getCurrentSession().delete(article); 

    } 

} 

而這裏的hibernatedataccesscontext文件:

<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context" 
    xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx" 
    xsi:schemaLocation=" 
     http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd 
     http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd 
     http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd 
     http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"> 

    <!-- Auto-detect the DAOs --> 
    <context:component-scan base-package="com.bd.dao"/> 
<!-- <context:component-scan base-package="com.bd.service"/> 
    <context:component-scan base-package="com.bd.controleur"/> --> 


    <context:property-placeholder location="WEB-INF/jdbc.properties"/> 


    <bean id="dataSource" 
     class="org.springframework.jdbc.datasource.DriverManagerDataSource"> 
     <property name="driverClassName" value="${database.driver}" /> 
     <property name="url" value="${database.url}" /> 
     <property name="username" value="${database.user}" /> 
     <property name="password" value="${database.password}" /> 
    </bean> 



    <bean id="sessionFactory" 
     class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> 
     <property name="dataSource" ref="dataSource" /> 
     <property name="annotatedClasses"> 
      <list> 
       <value>com.bd.entity.Article</value> 

      </list> 
     </property> 
     <property name="hibernateProperties"> 
      <props> 
       <prop key="hibernate.dialect">${hibernate.dialect}</prop> 
       <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>  
       <!-- generation base donnée  <prop key="hibernate.hbm2ddl.auto">create-drop</prop> --> 
     <prop key="hibernate.hbm2ddl.auto">create-drop</prop> 
      </props> 
     </property> 
     <property name="articleListeners"> 
     <map> 
     <entry key="merge"> 
      <bean class="org.springframework.orm.hibernate3.support.IdTransferringMergeArticleListener"/> 
     </entry> 
     </map> 
    </property> 
    </bean> 




    <tx:annotation-driven transaction-manager="txnManager"/> 

    <bean id="txnManager" 
     class="org.springframework.orm.hibernate3.HibernateTransactionManager" 
     p:sessionFactory-ref="sessionFactory"/> 

    <bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor"/> 

</beans> 


    et jdbc.properties 


database.driver=com.mysql.jdbc.Driver 
database.url=jdbc:mysql://localhost:3306/ccccc 
database.user=root 
database.password=root 
hibernate.dialect=org.hibernate.dialect.MySQL5Dialect 
hibernate.show_sql=true 

的問題是,沒有任何數據庫結構得到產生。請幫忙。

+0

Je crois que vous dois parler angle ici。 (原諒我的法語,我不是一個熟練的揚聲器) – Tom

+2

我剛剛提交了翻譯的編輯。英語是SO的標準語言,在用另一種語言提問時,你可能會發現只有有限的幫助。 Votreproblèmeest qu'aucune table estgénéréesur la base dedonnéesa partir de vos classes,correct? –

+1

你好,我想開發人員應用jee hibernate spring 我有一個類文章, 我嘗試生成數據庫,但它沒有生成 我沒有沒有錯誤在consol – achref05

回答

1

在您的Hibernate配置xml中,確保您有hibernate.hbm2ddl.auto設置爲update,createcreate-drop

+0

我添加了hibernate.hbm2ddl.auto和創建滴,它同樣的問題 – achref05

+0

請幫我 我有2天在這個問題 請 – achref05

+0

如果你仍然有這個問題,發佈你得到的錯誤,會有幫助(應該在你的日誌中)。 – Kraylog