-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: org.hibernate.MappingException:duplicate calss mapping:Cus..
PostPosted: Tue Dec 20, 2005 7:41 am 
Newbie

Joined: Tue Nov 29, 2005 6:33 am
Posts: 6
The program perfectly run on the java console.
But , when i tried to excute these things in servlet using Tomcat server it shows the following error

Thank u


Error:
Code:
org.hibernate.MappingException:Could not read mappings from resource :CustomerAccount
...............................................
................................................
caused by : org.hibernate.MappingException :duplicate calss mapping :CustomerAccount
.


Hibernate version:3.1

Mapping documents:hibernate.cfg.xml,AccountType.hbm.xml,AccountStatus.hbm.xml,CustomerAccount.hbm.xml

AccountType.hbm.xml:

Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
  <class name="AccountType" table="account_type" optimistic-lock="none">
    <id name="accountTypeId" type="short" unsaved-value="null" column="account_type_id">
      <generator class="native"/>
    </id>
    <property name="name" type="string" column="name" length="40" not-null="true"/>
    <property name="description" type="string">
      <column name="description" not-null="true"/>
    </property>
    <one-to-one name="customerAccount" entity-name="CustomerAccount" cascade="save-update" foreign-key="customer_account_ibfk_2" property-ref="accountTypeId"/>
  </class>
</hibernate-mapping>


AccountStatus.hbm.xml
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
  <class name="AccountStatus" table="account_status" optimistic-lock="none">
    <id name="accountStatusId" type="short" unsaved-value="null" column="account_status_id">
      <generator class="native"/>
    </id>
    <property name="name" type="string" column="name" length="40" not-null="true"/>
    <property name="description" type="string">
      <column name="description"/>
    </property>
    <one-to-one name="customerAccount" entity-name="CustomerAccount" cascade="save-update" foreign-key="customer_account_ibfk_1" property-ref="accountStatusId"/>
  </class>
</hibernate-mapping>

Code between sessionFactory.openSession() and session.close():
Code:
public class Main extends HttpServlet{
SessionFactory factory =null;
   
public void init() {
      try {
         
         Configuration config = new Configuration();
      /*   config.addClass(AccountStatus.class);
         config.addClass(AccountType.class);*/
         config.addClass(CustomerAccount.class);
         config.configure();
          factory= config.buildSessionFactory();
      
         System.out.println("Hibernate Successfully initialized");

          }catch(Exception e)
         {
            System.out.println("---------------------------------First try *--------------------------");   
            e.printStackTrace(System.out);
            System.out.println("---------------------------------First try *--------------------------");
         }
            }

   public void doPost(HttpServletRequest req,HttpServletResponse res)throws ServletException,IOException
         {

            res.setContentType("text/htm");
            PrintWriter out=res.getWriter();
            try
               {
         Session session = factory.openSession();
         AccountStatus acStatus=null;
         AccountType acType=null;
                  
         
            Transaction tx =  session.beginTransaction();
         
         
            Query query=session.createQuery("from AccountType as acType  where

acType.accountTypeId="+1);
             for(Iterator itr = query.iterate(); itr.hasNext(); ) {
                     acType = (AccountType)itr.next(); 
                 }
              query=session.createQuery("from AccountStatus as acStatus  where

acStatus.accountStatusId="+1);
             for(Iterator itr = query.iterate(); itr.hasNext(); ) {
                     acStatus = (AccountStatus)itr.next(); 
                 }
             CustomerAccount cusAccount = new CustomerAccount();
             cusAccount.setAccountStatusId(acStatus);
             cusAccount.setAccountTypeId(acType);
             cusAccount.setAddress1("Raj bavan");
             cusAccount.setAddress2("ddddd");
             cusAccount.setCity("New york");
             cusAccount.setCompanyName("Finocus inc.,");
             cusAccount.setCustomerId(new Long("65"));
             cusAccount.setFax(new Long("737373"));
             cusAccount.setState("Dubai");
             cusAccount.setSuite("848");
             cusAccount.setTelephone(new Long("3434"));
             cusAccount.setWww("wwww.google.com");
             cusAccount.setZip(new Integer("84848"));
            
         session.save(cusAccount);
         tx.commit();
         session.flush();
         session.close();
         
      System.out.println("Saved Successfully");
      }
      catch(Exception e)
      {
            System.out.println("---------------------------------Second try *--------------------------");
         e.printStackTrace(System.out);
            System.out.println("---------------------------------Second try *--------------------------");
            

      }

   }

}

Full stack trace of any exception that occurs:

Name and version of the database you are using:

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 20, 2005 9:27 am 
Senior
Senior

Joined: Tue May 10, 2005 9:00 am
Posts: 125
Could you provide the content of your hibernate.cfg.xml ?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 20, 2005 9:29 am 
Senior
Senior

Joined: Tue May 10, 2005 9:00 am
Posts: 125
And also CustomerAccount.hbm.xml :)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.