2012-03-25 15 views
1

私はhibernateを使用するプロジェクトを設定しています。クラスを作成し、.hbm.xmlファイルを書き込まないように注釈を追加しています。私はまた、DAOやデータベース作成のための達人特別hbm2daoプラグインHibernate3のとhbm2ddlを使用しようとしていますが、私はエラーはmavenプラグインでhibernate daoとddlを生成します

failed: Unable to load class declared as <mapping class=package.ClassName.....

hibernate.cfg.xmlのは、以下の取得:プラグインの

<hibernate-configuration> 
    <session-factory name="jndi/composite/SessionFactory"> 
     <property name="hibernate.c3p0.max_size">20</property> 
     <property name="hibernate.c3p0.max_statements">50</property> 
     <property name="hibernate.c3p0.min_size">5</property> 
     <property name="hibernate.c3p0.timeout">1800</property> 
     <property name="hibernate.connection.autocommit">false</property> 
     <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property> 
     <property name="hibernate.connection.password">PASS</property> 
     <property name="hibernate.connection.url">jdbc:mysql://localhost/DATABASE</property> 
     <property name="hibernate.connection.username">USER</property> 
     <property name="hibernate.current_session_context_class">thread</property> 
     <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property> 
     <property name="hibernate.show_sql">true</property> 
     <property name="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory </property> 
     <property name="hibernate.use_sql_comments">true</property> 
     <mapping class="package.....models.User"/> 
    </session-factory> 
</hibernate-configuration> 

設定をon pom.xml

<configuration> 
    <components>    
     <component> 
      <name>hbm2dao</name> 
      <implementation>annotationconfiguration</implementation> 
      <outputDirectory>target/generated-sources/hibernate3</outputDirectory> 
     </component> 
    </components> 
    <componentProperties> 
     <jdk5>true</jdk5> 
     <ejb3>false</ejb3> 
     <packagename>package......models</packagename> 
     <format>true</format> 
     <haltonerror>true</haltonerror> 
     <scan-classes>true</scan-classes> 
    </componentProperties> 
</configuration> 

私が忘れているかもしれない情報は、尋ねるだけで、ありがとう。

+0

「あなたは」として宣言されたクラスをロードできませんでしたか? –

+0

フォーマットが正しくありませんでした。現在は表示されています。 – LoneWolf

答えて

1

私の主な問題は、私の主な問題は、hibernate.cfg.xmlでクラスを使用すると、コンパイルされたクラスを使用し、私がここでとにかく考えていたソースではなく、 。

<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-compiler-plugin</artifactId> 
    <version>2.3.2</version> 
    <executions> 
     <execution> 
      <id>compile-hibernate-classes</id> 
      <phase>generate-sources</phase> 
      <goals> 
       <goal>compile</goal> 
      </goals> 
      <configuration> 
       <includes> 
        <include>FILTER_TO_INCLUDE_HIBERNATE_CLASSES</include> 
       </includes> 
      </configuration> 
     </execution> 
     <execution> 
      <id>compile-all</id> 
      <phase>compile</phase> 
      <goals> 
       <goal>compile</goal> 
      </goals> 
     </execution> 
    </executions> 
</plugin>  

<plugin> 
    <groupId>org.codehaus.mojo</groupId> 
    <artifactId>hibernate3-maven-plugin</artifactId> 
    <version>2.2</version> 
    <executions> 
     <execution> 
      <phase>generate-sources</phase> 
      <goals> 
       <goal>hbm2dao</goal> 
      </goals> 
     </execution> 
    </executions> 
    <configuration> 
     <components> 
      <component> 
       <name>hbm2dao</name> 
       <implementation>annotationconfiguration</implementation> 
       <outputDirectory>target/generated-sources/hibernate3</outputDirectory> 
      </component> 
      <component> 
       <name>hbm2ddl</name> 
       <implementation>annotationconfiguration</implementation> 
       <outputDirectory>target/generated-sources/hibernate3</outputDirectory> 
      </component> 
     </components> 
     <componentProperties> 
      <jdk5>true</jdk5> 
      <ejb3>false</ejb3> 
      <packagename>PACKAGE_GOES_HERE</packagename> 
      <haltonerror>true</haltonerror> 
     </componentProperties> 
    </configuration> 
</plugin> 

だから、コンパイラプラグインの最初の実行は、DAOクラスを生成するのに必要なだけのクラスをコンパイルし、第二は、すべてをコンパイルします。 hibernateプラグインでの実行は、コンパイル時にdaoクラスが生成されることを確認します。

私にとって最良の方法ではないかもしれませんが、私のために働きます。

関連する問題