Announcement Announcement Module
Collapse
No announcement yet.
An AnnotationConfiguration instance is required to use <mapping class=" Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • An AnnotationConfiguration instance is required to use <mapping class="

    I am getting the error msg when I am trying to run as "ant schemaexport"

    here is my script--

    <target name="schemaexport">

    <taskdef name="schemaexport"
    classpathref="classpath"
    classname="org.hibernate.tool.hbm2ddl.SchemaExport Task"
    >
    </taskdef >

    <schemaexport
    config="${buildDir}/hibernate.cfg.xml"
    quiet="no"
    text="no"
    drop="no"
    delimiter=";"
    output="schema-export.sql">
    <fileset dir="src">
    <include name="${buildDir}/applicationContext-hibernate.xml"/>
    </fileset>
    </schemaexport>


    </target>

    hibernate.cfg.xml---

    <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

    <hibernate-configuration>
    <session-factory>
    <!--
    we have the dialect property here so we can generate schema correctly
    the rest are dynamic based on if we are in testing or not
    -->
    <property name="hibernate.cache.use_query_cache">false</property>
    <property name="hibernate.cache.use_second_level_cache">fals e</property>
    <property name="hiberante.cache.jndi"></property>
    <property name="dialect">org.hibernate.dialect.Oracle9Dialec t</property>
    <mapping class="com.xxx.xxx.xxx..Activity"/>


    </session-factory>

    </hibernate-configuration>

    Please reply me asap

  • #2
    Can anyone reply??

    Can anyone reply??

    Comment


    • #3
      re: An AnnotationConfiguration instance is required to use &lt;mapping class=

      I'm responding to this old post because nobody else has and I spent a few hours figuring out the same problem.

      The book "Java Persistence with Hibernate" by Bauer and King shows a complete ant task for the hibernate tool. This works when you use the old style XML mappings. If you use the new style annotations to describe the mappings, then you have to change the ant task slightly - replace the <configuration> tag with an <annotationconfiguration> tag. The tag parameters are the same. For example:

      <configuration configurationfile="${class.dir}/hibernate.cfg.xml"/>

      becomes

      <annotationconfiguration configurationfile="${class.dir}/hibernate.cfg.xml"/>

      This is mentioned very briefly in the book (page 71 in my copy), but it's easy to miss.

      Comment


      • #4
        A solution

        Hi, I noticed this thread is quite old, but I will write here my solution in case anyone ever needs it.

        So I am working on an old project, which used hibernate 3.0.5. We upgraded to 3.6.10.Final. And we were usind two databases and one was smaller we decided to change the configuration of our entities from xdoclet annotations & hbm.xml files to JPA annotations.

        The test database was generated using an Ant task that executed this class org.hibernate.tool.hbm2ddl.SchemaExportTask with the following setting:
        Code:
        <taskdef name="schemaexport" classname="org.hibernate.tool.hbm2ddl.SchemaExportTask">
                    <classpath>
                        <path refid="xdoclet.classpath" />
                        <path refid="hibernate.classpath" />
                    </classpath>
        </taskdef>
        <schemaexport quiet="no" text="no" drop="no" delimiter=";"
                              properties="${somepath}/database.properties"
                              output="${somepath}/schemaexportlog.sql">
                    <fileset dir="${somepath}/dao/src/main/resources" includes="**/*.hbm.xml" />
         </schemaexport>
        The solution was to add another task but with a different configuration.
        Code:
        <taskdef name="annschemaexport" classname="org.hibernate.tool.hbm2ddl.SchemaExportTask">
                    <classpath>
                        <path refid="xdoclet.classpath"/>
                        <path refid="hibernate.classpath"/>
                    </classpath>
        </taskdef>
         <annschemaexport quiet="no" text="no" drop="no" delimiter=";"
                                 properties="${somepath}/dao/src/test/resources/database.properties"
                                 output="${somepath}/schemaexportlog.sql"
                                 config="${somepath}/dao/src/main/resources/META-INF/hibernate.cfg.xml"/>
        I had no choice but to put my annotated classes in a hibernate.cfg.xml file, but it was worth it.
        My hibernate.cfg.xml file:
        Code:
        <?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>
                <mapping class="pack.EntityOne"/>
                <mapping class="pack.EntityTwo"/>
            </session-factory>
        </hibernate-configuration>
        And this file can be used to configure a spring AnnotationSessionFactoryBean instance like this:
        Code:
        <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
                <property name="dataSource" ref="dataSource"/>
                <property name="configLocation" value="classpath:META-INF/hibernate.cfg.xml"/>
                <property name="hibernateProperties">
                   <props>
                        <prop key="hibernate.dialect">${hibernate.dialect}</prop>
                        <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
                        <!-- Create/update the database tables automatically when the JVM starts up -->
                        <prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>
                   [etc]
               </property>
        </bean>
        I hope these details are enough for for everyone to be able to implememnt this. In case I am missing something, I will come back later and add more details based on your feedback!
        Happy coding!
        Last edited by iuliana.cosmina; Apr 30th, 2013, 04:49 AM.

        Comment

        Working...
        X