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.xmlAccountType.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.xmlCode:
<?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: