4

When I run the project, it occurs an exception as below. Before I add a view table in Hibernate, everyting got well include the Blame.hbm.xml and others. And it could read the data from database. The exception occurs in ShowOrderDaoImpl.java at this sentence: session=HibernateSessionFactory.getSession();

My exception

    org.hibernate.InvalidMappingException: Could not parse mapping document from resource pojo/Blame.hbm.xml
    at org.hibernate.cfg.Configuration$MetadataSourceQueue.processHbmXml(Configuration.java:3415)
    at org.hibernate.cfg.Configuration$MetadataSourceQueue.processHbmXmlQueue(Configuration.java:3404)
    at org.hibernate.cfg.Configuration$MetadataSourceQueue.processMetadata(Configuration.java:3392)
    at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1341)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1737)
    at session.factory.HibernateSessionFactory.rebuildSessionFactory(HibernateSessionFactory.java:75)
    at session.factory.HibernateSessionFactory.getSession(HibernateSessionFactory.java:57)
    at dao.impl.ShowOrderDaoImpl.queryTradesByBid(ShowOrderDaoImpl.java:24)
    at test.testHibernate.main(testHibernate.java:45)
Caused by: org.hibernate.DuplicateMappingException: Duplicate class/entity mapping pojo.Blame
ok
    at org.hibernate.cfg.Configuration$MappingsImpl.addClass(Configuration.java:2580)
    at org.hibernate.cfg.HbmBinder.bindRoot(HbmBinder.java:174)
    at org.hibernate.cfg.Configuration$MetadataSourceQueue.processHbmXml(Configuration.java:3412)
    ... 8 more
java.lang.NullPointerException
    at dao.impl.ShowOrderDaoImpl.queryTradesByBid(ShowOrderDaoImpl.java:25)
    at test.testHibernate.main(testHibernate.java:45)

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">
<hibernate-configuration>
 <session-factory>
  <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
  <property name="hibernate.connection.password">root</property>
  <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/disputesystem</property>
  <property name="hibernate.connection.username">root</property>
  <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
  <property name="hibernate.show_sql">true</property>
  <mapping resource="pojo/Blame.hbm.xml"/>
  <mapping resource="pojo/Buyer.hbm.xml"/>
  <mapping resource="pojo/Dispute.hbm.xml"/>
  <mapping resource="pojo/Evidence.hbm.xml"/>
  <mapping resource="pojo/Goods.hbm.xml"/>
  <mapping resource="pojo/Message.hbm.xml"/>
  <mapping resource="pojo/Record.hbm.xml"/>
  <mapping resource="pojo/Seller.hbm.xml"/>
  <mapping resource="pojo/Staff.hbm.xml"/>
  <mapping resource="pojo/Trade.hbm.xml"/>
  <mapping resource="pojo/Fund.hbm.xml"/>
  <mapping resource="pojo/Showorderbybid.hbm.xml"/>
 </session-factory>
</hibernate-configuration>

my ShowOrderDaoImpl.java file

package dao.impl;

import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;

import pojo.Showorderbybid;
import session.factory.HibernateSessionFactory;
import dao.intf.ShowOrderDao;

public class ShowOrderDaoImpl implements ShowOrderDao{

    @Override
    public List<Showorderbybid> queryTradesByBid(String bid) throws Exception {
        Session session=null;
        Transaction transaction=null;
        List<Showorderbybid> orders=new ArrayList<Showorderbybid>();
        try {
            session=HibernateSessionFactory.getSession();
            transaction=session.beginTransaction();
            Query query=session.createQuery("from Showorderbybid where bid=?");
            query.setParameter(0, bid);
            orders=(List<Showorderbybid>)query.list();
            List CountView = new ArrayList(); 
            Iterator it = orders.iterator(); 
            while (it.hasNext()) {
                Object[] all = (Object[]) it.next(); 
                Showorderbybid countViewId = new Showorderbybid(); 
                countViewId.setAmount((Integer) all[0]); 
                countViewId.setBid((String) all[1]); 
                countViewId.setDetail((String) all[2]); 
                countViewId.setGid((String)all[3]); 
                countViewId.setGname((String)all[4]);
                countViewId.setLogistics((String)all[5]);
                countViewId.setSid((String)all[6]);
                countViewId.setSname((String)all[7]);
                countViewId.setStatus((String)all[8]);
                countViewId.setTid((String)all[9]);
                countViewId.setTotalmoney((Integer) all[10]);
                countViewId.setTradetime((Date)all[11]);
                orders.add(countViewId);  
            } 

        } catch (Exception e) {
            e.printStackTrace(); 
        }finally{
            HibernateSessionFactory.closeSession();
        }
        return orders;
    }

}

my Blame.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">
<!-- Generated 2013-4-19 23:02:05 by Hibernate Tools 3.4.0.CR1 -->
<hibernate-mapping>
    <class name="pojo.Blame" table="blame" catalog="disputesystem">
        <id name="id" type="java.lang.Integer">
            <column name="id" />
            <generator class="identity" />
        </id>
        <many-to-one name="dispute" class="pojo.Dispute" fetch="select">
            <column name="disputeid" length="20" not-null="true" />
        </many-to-one>
        <property name="blametime" type="timestamp">
            <column name="blametime" length="19" not-null="true" />
        </property>
        <property name="content" type="string">
            <column name="content" length="1000" />
        </property>
    </class>
</hibernate-mapping>
4
  • the exception occurs in ShowOrderDaoImpl.java at this sentence: session=HibernateSessionFactory.getSession(); Commented Apr 20, 2013 at 8:49
  • Showorderbybid is the view Commented Apr 20, 2013 at 8:51
  • Did your original xml file contain extra spaces before <?xml version="1.0"?> ? It shouldn't be there. Commented Apr 20, 2013 at 8:56
  • It is format error. I delete the spaces already. Commented Apr 20, 2013 at 9:04

3 Answers 3

3

Looks like there is another mapping for pojo.Blame. You might had a copy/paste mistake:

<class name="pojo.Blame"

In another hbm file.

This

Caused by: org.hibernate.DuplicateMappingException: Duplicate class/entity mapping pojo.Blame

States that when reached a hbm file it already has a definition for a class named pojo.Blame.

Looks like in some of this files:

<mapping resource="pojo/Blame.hbm.xml"/>
<mapping resource="pojo/Buyer.hbm.xml"/>
<mapping resource="pojo/Dispute.hbm.xml"/>
<mapping resource="pojo/Evidence.hbm.xml"/>
<mapping resource="pojo/Goods.hbm.xml"/>
<mapping resource="pojo/Message.hbm.xml"/>
<mapping resource="pojo/Record.hbm.xml"/>
<mapping resource="pojo/Seller.hbm.xml"/>
<mapping resource="pojo/Staff.hbm.xml"/>
<mapping resource="pojo/Trade.hbm.xml"/>
<mapping resource="pojo/Fund.hbm.xml"/>
<mapping resource="pojo/Showorderbybid.hbm.xml"/>

Is a misplaced <class name="pojo.Blame"

Sign up to request clarification or add additional context in comments.

4 Comments

You mean where I should paste class name="pojo.Blame" to. Or which sentence should be replaced?
Yeah, this answer seems the most logical Duplicate class/entity mapping pojo.Blame. There is a typo somewhere in some hbm file. You have copy pasted your hbm files and forgotten to change the mapping / table.
Thank you, however I have checked all of my hbm files, there are correct class name as well as its table names. Hence I guess it is not the copy/paste issue. And before I add a view into Hibernate, my project runs well. I guess the problem in the view table "Showorderbybid".
Even I delete <mapping resource="pojo/Blame.hbm.xml" /> from hibernate.cfg.xml. It caused the same issue while the table changed to Buyer.hbm.xml.
0

be sure that you have overrided the equals/tostring and hash methodes in your Pojo

Comments

-2

check why the session=HibernateSessionFactory.getSession(); is getting null. That is the reason for the null pointer

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.