facebook

org.hibernate.MappingException: duplicate import

  1. MyEclipse Archived
  2.  > 
  3. Database Tools (DB Explorer, Hibernate, etc.)
Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #248936 Reply

    malibarreiro
    Member

    Hello,
    I trie to execute my application and I receive this error:

    
    %%%% Error Creating SessionFactory %%%%
    org.hibernate.MappingException: Error reading resource: com/innova/siom2/bd/OfertaMd.hbm.xml
        at org.hibernate.cfg.Configuration.addResource(Configuration.java:452)
        at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1263)
        at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1235)
        at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1217)
        at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1184)
        at org.hibernate.cfg.Configuration.configure(Configuration.java:1112)
        at com.innova.siom2.bd.HibernateSessionFactory.currentSession(HibernateSessionFactory.java:48)
        at com.innova.siom2.regles.ManagerOferta.procesarOfertaMI(ManagerOferta.java:43)
        at com.innova.siom2.test.Pruebas.main(Pruebas.java:32)
    Caused by: org.hibernate.MappingException: duplicate import: com.innova.siom2.bd.OfertaMd
        at org.hibernate.cfg.Mappings.addImport(Mappings.java:105)
        at org.hibernate.cfg.HbmBinder.bindPersistentClassCommonValues(HbmBinder.java:541)
        at org.hibernate.cfg.HbmBinder.bindClass(HbmBinder.java:488)
        at org.hibernate.cfg.HbmBinder.bindRootClass(HbmBinder.java:234)
        at org.hibernate.cfg.HbmBinder.bindRoot(HbmBinder.java:152)
        at org.hibernate.cfg.Configuration.add(Configuration.java:362)
        at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:400)
        at org.hibernate.cfg.Configuration.addResource(Configuration.java:449)
        ... 8 more
    %%%% Error Creating SessionFactory %%%%
    org.hibernate.MappingException: Error reading resource: com/innova/siom2/bd/OfertaMd.hbm.xml
        at org.hibernate.cfg.Configuration.addResource(Configuration.java:452)
        at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1263)
        at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1235)
        at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1217)
        at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1184)
        at org.hibernate.cfg.Configuration.configure(Configuration.java:1112)
        at com.innova.siom2.bd.HibernateSessionFactory.currentSession(HibernateSessionFactory.java:48)
        at com.innova.siom2.regles.ManagerOferta.procesarOfertaMI(ManagerOferta.java:44)
        at com.innova.siom2.test.Pruebas.main(Pruebas.java:32)
    Caused by: org.hibernate.MappingException: duplicate import: com.innova.siom2.bd.OfertaMd
        at org.hibernate.cfg.Mappings.addImport(Mappings.java:105)
        at org.hibernate.cfg.HbmBinder.bindPersistentClassCommonValues(HbmBinder.java:541)
        at org.hibernate.cfg.HbmBinder.bindClass(HbmBinder.java:488)
        at org.hibernate.cfg.HbmBinder.bindRootClass(HbmBinder.java:234)
        at org.hibernate.cfg.HbmBinder.bindRoot(HbmBinder.java:152)
        at org.hibernate.cfg.Configuration.add(Configuration.java:362)
        at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:400)
        at org.hibernate.cfg.Configuration.addResource(Configuration.java:449)
        ... 8 more
    

    I post my hibernate.cfg.xml:

    
    [size=9][/size]
    <?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">
    
    <!-- Generated by MyEclipse Hibernate Tools.                   -->
    <hibernate-configuration>
    
    <session-factory>
        <property name="myeclipse.connection.profile">siom2</property>
        <property name="connection.url">jdbc:mysql://192.168.100.5:3307/Siom2</property>
        <property name="connection.username">innova</property>
        <property name="connection.password">runptysql</property>
        <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
        <mapping resource="com/innova/siom2/bd/OfertaMd.hbm.xml"></mapping>
        <mapping resource="com/innova/siom2/bd/OfertaMi.hbm.xml"></mapping>
        <mapping resource="com/innova/siom2/bd/OfertaMidetalle.hbm.xml"></mapping>
        <mapping resource="com/innova/siom2/bd/OfertaMddetalle.hbm.xml"></mapping>
        <mapping resource="com/innova/siom2/bd/Pdvd.hbm.xml"></mapping>
        <mapping resource="com/innova/siom2/bd/Pdvddetalle.hbm.xml"></mapping>
        <mapping resource="com/innova/siom2/bd/Pibca.hbm.xml"></mapping>
        <mapping resource="com/innova/siom2/bd/Pibcadetalle.hbm.xml"></mapping>
        <mapping resource="com/innova/siom2/bd/Pibci.hbm.xml"></mapping>
        <mapping resource="com/innova/siom2/bd/Pibcidetalle.hbm.xml"></mapping>
    </session-factory>
    
    </hibernate-configuration>
    
    


    And the file OfertaMd.hbm.xml

    [size=9][/size]
    <?xml version="1.0"?>
    <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
    <!-- 
        Mapping file autogenerated by MyEclipse - Hibernate Tools
    -->
    <hibernate-mapping package="com.innova.siom2.bd">
        <class name="OfertaMd" table="OfertaMD">
            <id name="idOfertaMd" type="java.lang.Integer">
                <column name="Id_OfertaMD" />
                <generator class="native" />
            </id>
            <property name="fecha" type="java.util.Date">
                <column name="fecha" length="19" not-null="true" />
            </property>
            <property name="nroHora" type="java.lang.Short">
                <column name="nroHora" not-null="true" />
            </property>
            <property name="energia" type="java.lang.Float">
                <column name="energia" precision="12" scale="0" not-null="true" />
            </property>
            <set name="ofertaMddetalles" inverse="true" cascade = "all">
                <key column="id_OfertaMD" not-null="true" />
                <one-to-many class="OfertaMddetalle" />
            </set>
        </class>
    </hibernate-mapping>
    


    I think that the error doesn’t ocurre only in ofertasMd. It happend in this file because its the first in the hibernate.cfg.xml. If I change the sort of the mapping ressource list, the error appears in other file, the first in the mapping ressource list of the hibernate.cfg.xml.
    Thank you very much

    #248981 Reply

    Haris Peco
    Member

    malibarreiro ,

    Please, can you send us you configuration class (HibernaetUtil or what ever) and describe environment (standalone, application server …)
    Check, if your hibernate.cfg.xml first in classpath (it is possible that hibernate grab another file with duplicate mappings)
    You have duplicate mapping, definitely and you have to find how. I will try help you if you send me more details

    Regards

    #249300 Reply

    arao06
    Member

    Hello,

    I’m receiving a similar error when I run my application. Has anyone resolved this problem yet? I would appreciate any insight into this problem!

    #249301 Reply

    Haris Peco
    Member

    I can reporduce your problem with mapping resource twice in cfg.xml

    you have mapping twice or in cfg.xml, or in session configuration (making session factory) – I think that you have
    2 or more hibernate.cfg.xml in classpath and hibernate grab some with double mappings

    check your confgiuration

    #249405 Reply

    arao06
    Member

    Thanks for your response. I looked in directories in my workspace. I found that I do have 2 hibernate.cfg.xml files however one of them is created by Eclipse when I compile my application. I have one file in /src (which is the one eclipse prompted me to create when I added hibernate capabilities to my project). The other one is crated by Eclipse and resides in the WebRoot/WEB-INF/classes folder. I tried deleting the file in /src folder but it didn’t make any difference. I
    still got the same error. I then put the file back and tried deleting the one in the WebRoot/WEB-INF/classes folder. When I compiled and deployed the app, I found that eclipse had created the file again in the WebRoot folder and I still got the error. Following are the error details and my hibernate.cfg.xml file:

    org.hibernate.MappingException: Error reading resource: com/osb/entities/Scrapbooks.hbm.xml
    at org.hibernate.cfg.Configuration.addResource(Configuration.java:452)
    at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1263)
    at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1235)
    at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1217)
    at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1184)
    at org.hibernate.cfg.Configuration.configure(Configuration.java:1112)
    at com.osb.hibernate.HibernateSessionFactory.currentSession(HibernateSessionFactory.java:48)
    at com.osb.broker.ScrapbookBroker.getCurrentSession(ScrapbookBroker.java:40)
    at com.osb.struts.action.CreateScrapbookAction.execute(CreateScrapbookAction.java:56)
    at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
    at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
    at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
    at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:767)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:860)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:585)
    at org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:249)
    at java.security.AccessController.doPrivileged(Native Method)
    at javax.security.auth.Subject.doAsPrivileged(Subject.java:517)
    at org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java:282)
    at org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:165)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:257)
    at org.apache.catalina.core.ApplicationFilterChain.access$000(ApplicationFilterChain.java:55)
    at org.apache.catalina.core.ApplicationFilterChain$1.run(ApplicationFilterChain.java:161)
    at java.security.AccessController.doPrivileged(Native Method)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:263)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:551)
    at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:225)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:173)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:551)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:551)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:132)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:551)
    at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:933)
    at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:189)
    at com.sun.enterprise.web.connector.grizzly.ProcessorTask.doProcess(ProcessorTask.java:604)
    at com.sun.enterprise.web.connector.grizzly.ProcessorTask.process(ProcessorTask.java:475)
    at com.sun.enterprise.web.connector.grizzly.ReadTask.executeProcessorTask(ReadTask.java:371)
    at com.sun.enterprise.web.connector.grizzly.ReadTask.doTask(ReadTask.java:264)
    at com.sun.enterprise.web.connector.grizzly.TaskBase.run(TaskBase.java:281)
    at com.sun.enterprise.web.connector.grizzly.WorkerThread.run(WorkerThread.java:83)
    Caused by: org.hibernate.MappingException: duplicate import: com.osb.entities.Scrapbooks
    at org.hibernate.cfg.Mappings.addImport(Mappings.java:105)
    at org.hibernate.cfg.HbmBinder.bindPersistentClassCommonValues(HbmBinder.java:541)
    at org.hibernate.cfg.HbmBinder.bindClass(HbmBinder.java:488)
    at org.hibernate.cfg.HbmBinder.bindRootClass(HbmBinder.java:234)
    at org.hibernate.cfg.HbmBinder.bindRoot(HbmBinder.java:152)
    at org.hibernate.cfg.Configuration.add(Configuration.java:362)
    at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:400)
    at org.hibernate.cfg.Configuration.addResource(Configuration.java:449)
    … 45 more
    |#]

    My hibernate.cfg.xml file:

    ?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”&gt;

    <!– Generated by MyEclipse Hibernate Tools. –>
    <hibernate-configuration>

    <session-factory>
    <property name=”myeclipse.connection.profile”>osb_database</property>
    <property name=”connection.url”>jdbc:mysql://localhost/myosb</property>
    <property name=”connection.username”>root</property>
    <property name=”connection.password”>Y0s3m1t3</property>
    <property name=”connection.driver_class”>com.mysql.jdbc.Driver</property>
    <property name=”dialect”>org.hibernate.dialect.MySQLDialect</property>
    <property name=”transaction.factory_class”>org.hibernate.JDBCTransactionFactory</property>
    <mapping resource=”com/osb/entities/Scrapbooks.hbm.xml” />
    <mapping resource=”com/osb/entities/Scrapbookpages.hbm.xml” />
    <mapping resource=”com/osb/entities/Scrapbookowners.hbm.xml” />

    </session-factory>

    </hibernate-configuration>

    My scrapbooks.hbm.xml file:

    ?xml version=”1.0″?>
    <!DOCTYPE hibernate-mapping PUBLIC “-//Hibernate/Hibernate Mapping DTD 3.0//EN”
    http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd”&gt;
    <!–
    Mapping file autogenerated by MyEclipse – Hibernate Tools
    –>
    <hibernate-mapping>
    <class name=”com.osb.entities.Scrapbooks” table=”scrapbooks” catalog=”myosb”>
    <id name=”sbId” type=”java.lang.Integer”>
    <column name=”Sb_id” />
    <generator class=”native”></generator>
    </id>
    <property name=”sbName” type=”java.lang.String”>
    <column name=”SbName” length=”50″ />
    </property>
    <property name=”sbCat” type=”java.lang.String”>
    <column name=”SbCat” length=”50″ />
    </property>
    <property name=”sbUserid” type=”java.lang.String”>
    <column name=”SbUserid” length=”20″ />
    </property>
    </class>
    </hibernate-mapping>

    Just for clarity – my application is web based and deployed on the sun web server. It uses struts as well. This is my first application with hibernate and I’m stumped as to why I’m getting the error. I followed all the instructions in eclipse for adding hibernate capabilities and it created the mapping files and the hibernate.cfg.xml file for me. The application itself is very simple and doesn’t really do anything complicated which could cause a problem. I would greatly appreciate any help rendered!
    Thanks very much

    #249417 Reply

    Haris Peco
    Member

    arao06,

    It is fine that you have hibernate.cfg.xml in src and classes directories – src is source directories and classes is bin – eclipse builder compile and send *.class (and all resources like *xml, images etc) in bin directory.
    I don’t sure that your new error is duplicate import – it can be scrapbook.hbm.xml instead Scrapbook.hbm.xml
    However, you check your deployment directory (sun server) and hibernate.cfg.xml in classes or some web libraries in deployment application

    Best regards

    #250096 Reply

    AllynCarter
    Member

    I had this problem at one point.
    I fixed it by doing a full clean and rebuild of my project. Hope it works for you, too.

    #272756 Reply

    tjphilpot
    Member

    The HibernateSessionFactory.getSession() method generated by MyEclipse 5.1.1 is not thread safe.

    Here is the original code:

    /**
         * Returns the ThreadLocal Session instance.  Lazy initialize
         * the <code>SessionFactory</code> if needed.
         *
         *  @return Session
         *  @throws HibernateException
         */
        public static Session getSession() throws HibernateException {
            Session session = (Session) threadLocal.get();
    
            if (session == null || !session.isOpen()) {
                if (sessionFactory == null) {
                    rebuildSessionFactory();
                }
                session = (sessionFactory != null) ? sessionFactory.openSession()
                        : null;
                threadLocal.set(session);
            }
    
            return session;
        }

    Here is a version that works in a multi-threaded environment:

    
        /**
         * Returns the ThreadLocal Session instance.  Lazy initialize
         * the <code>SessionFactory</code> if needed.
         *
         *  @return Session
         *  @throws HibernateException
         */
        public static Session getSession() throws HibernateException 
        {
            StringBuffer buf = null;
            
            Session session = (Session) threadLocal.get();
    
            if (session == null || !session.isOpen())     {
                // lazy initialization of internal instance.  First check if there
                // is an instance.  There can be multiple threads that find that
                // this evaluates to true.    
                if (sessionFactory == null) 
                {
                    // synchronize with the class to make sure two threads don't attempt to
                    // create the same factory twice.
                    synchronized (HibernateSessionFactory.class)
                    {
                        // need to check again that factory is null b/c a thread
                        // could be queued up waiting for the lock.  This test will
                        // let a thread know if it needs to actually create the instance.
                        if (sessionFactory == null)
                        {
                            // log that
                            if (LOGGER.isDebugEnabled())
                            {
                                buf = new StringBuffer();
                                buf.append(" : getSession()");
                                buf.append(" : Rebuilding Session Factory");
    
                                LOGGER.debug(buf.toString());
                            }
                            rebuildSessionFactory();
                        }
                    }
                    
                }
                else
                {
                    // log that the session has already been created
                    if (LOGGER.isDebugEnabled())
                    {
                        buf = new StringBuffer();
                        buf.append(" : getSession()");
                        buf.append(" : Session Factory has already been created.");
    
                        LOGGER.debug(buf.toString());
                    }
                }
        
                session = (sessionFactory != null) ? sessionFactory.openSession()
                        : null;
                threadLocal.set(session);
            }
    
            return session;
        }
    

    Thanks to Rob F. for pointing this out for our team.

    #304194 Reply

    mansley
    Member

    I just ran into this problem (using hibernate and jboss with MyEclipseIDE version 8.0), and resolved it my copying the above code into my HibernateSessionFactory. This seems to be quite an old issue, and I would have thought that the hibernate generator would have been updated by now. Is there some other issue that I am missing?

    #304308 Reply

    Loyal Water
    Member

    The dev team has been alerted about this. Thank you for letting us know.

    #332222 Reply

    hamedrafati
    Member

    By doing Project>Clean… problem Fixed 🙂 thanks

Viewing 11 posts - 1 through 11 (of 11 total)
Reply To: org.hibernate.MappingException: duplicate import

You must be logged in to post in the forum log in