Hi, I am new to hibernate and am experiencing an errot "org.hibernate.MappingException: Unknown entity:"trying to persist data. I have used import javax.persistence.Entity; and import javax.persistence.Id;. Kindly Help
Complete Error Log is org.hibernate.MappingException: Unknown entity: com.org.ui.pc.shared.model.Contract at org.hibernate.internal.SessionFactoryImpl.getEntityPersister(SessionFactoryImpl.java:1129) at org.hibernate.internal.SessionImpl.getEntityPersister(SessionImpl.java:1402) at org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:117) at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:204) at org.hibernate.event.internal.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:55) at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:189) at org.hibernate.event.internal.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:49) at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:90) at org.hibernate.internal.SessionImpl.fireSave(SessionImpl.java:756) at org.hibernate.internal.SessionImpl.save(SessionImpl.java:748) at org.hibernate.internal.SessionImpl.save(SessionImpl.java:744) at com.org.ui.pc.shared.model.TempMain.SaveContract(TempMain.java:43) at com.org.ui.pc.shared.model.TempMain.main(TempMain.java:24)
The following is my hibernate.cfg.xml
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> <hibernate-configuration> <!-- a SessionFactory instance listed as /jndi/name --> <session-factory name="java:hibernate/SessionFactory"> <!-- Database connection settings --> <property name="connection.driver_class">org.postgresql.Driver</property> <property name="connection.url">jdbc:postgresql://localhost:5432/pcdb</property> <property name="connection.username">postgres</property> <property name="connection.password">Postgr*5</property> <!-- JDBC connection pool (use the built-in) --> <property name="connection.pool_size">1</property> <!-- SQL dialect --> <property name="dialect">org.hibernate.dialect.PostgreSQLDialect</property> <!-- Enable Hibernate's automatic session context management --> <property name="current_session_context_class">thread</property> <!-- Disable the second-level cache --> <property name="cache.provider_class">org.hibernate.cache.internal.NoCacheProvider</property> <!-- Echo all executed SQL to stdout --> <property name="show_sql">true</property> <!-- Drop and re-create the database schema on startup --> <property name="hbm2ddl.auto">create</property> <!-- Names the annotated entity class --> <mapping class="com.org.ui.pc.shared.model.Contract"/> </session-factory>
</hibernate-configuration>
My Bean is
package com.org.ui.pc.shared.model;
import java.sql.Timestamp;
import javax.persistence.Entity; import javax.persistence.Id;
import com.extjs.gxt.ui.client.data.BaseTreeModel; import com.extjs.gxt.ui.client.data.BeanModelTag;
@SuppressWarnings("serial") @Entity public class Contract extends BaseTreeModel implements BeanModelTag{ @Id private String ContractId; private Contract Parent; private String ParentId; private Contract Template; private String TemplateId; private String Version; private String FinancialYear; private String Cycle; private String Status; private String CreatedBy; private Timestamp CreatedOn; private String ModifiedBy; private Timestamp ModifiedOn; private String Description; private String desc = ""; public Contract(){ } public Contract(String contractId){ setContractId(contractId); } public Contract(String version, String status) { setVersion(version); setStatus(status); } public Contract(String financialYear, String cycle, Contract[] contract) { setCycle(cycle); setFinancialYear(financialYear); for (int i = 0; i < contract.length; i++) { add(contract[i]); } } public Contract(String financialYear, String cycle, String version) { setCycle(cycle); setFinancialYear(financialYear); setVersion(version); } /*Implementations*/ /** * @return the Concantenated Description of the Period */ public String getDescription() { return Description; } /** * @return the contractId */ public String getContractId() { return ContractId; } /** * @param contractId the contractId to set */ public void setContractId(String contractId) { this.ContractId=contractId; } /** * @param Description the contractId to set */ public void setDescription(String description) { String ds = getDescription(); if(ds==null) ds =""; ds = ds +description; this.Description=ds; } /** * @return the parentId */ public String getParentId() { return ParentId; } /** * @param parentId the parentId to set */ public void setParentId(String parentId) { this.ParentId=parentId; } /** * @return the version */ public String getVersion() { return Version; } /** * @param version the version to set */ public void setVersion(String version) { setDescription(version); this.Version=version; } /** * @return the financialYear */ public String getFinancialYear() { return FinancialYear; } /** * @param financialYear the financialYear to set */ public void setFinancialYear(String financialYear) { setDescription("-"+financialYear); this.FinancialYear=financialYear; } /** * @return the cycle */ public String getCycle() { return Cycle; } /** * @param cycle the cycle to set */ public void setCycle(String cycle) { setDescription(cycle); this.Cycle=cycle; } /** * @return the status */ public String getStatus() { return Status; } /** * @param status the status to set */ public void setStatus(String status) { setDescription(" ("+status+")") ; this.Status=status; } /** * @return the createdBy */ public String getCreatedBy() { return CreatedBy; } /** * @param createdBy the createdBy to set */ public void setCreatedBy(String createdBy) { this.CreatedBy=createdBy; } /** * @return the createdOn */ public Timestamp getCreatedOn() { return CreatedOn; } /** * @param createdOn the createdOn to set */ public void setCreatedOn(Timestamp createdOn) { this.CreatedOn=createdOn; } /** * @return the modifiedBy */ public String getModifiedBy() { return ModifiedBy; } /** * @param modifiedBy the modifiedBy to set */ public void setModifiedBy(String modifiedBy) { this.ModifiedBy=modifiedBy; } /** * @return the modifiedOn */ public Timestamp getModifiedOn() { return ModifiedOn; } /** * @param modifiedOn the modifiedOn to set */ public void setModifiedOn(Timestamp modifiedOn) { this.ModifiedOn=modifiedOn; } /** * @return the parent */ public Contract getParent() { return Parent; } /** * @param parent the parent to set */ public void setParent(Contract parent) { this.Parent=parent; } /** * @return the template */ public Contract getTemplate() { return Template; } /** * @param template the template to set */ public void setTemplate(Contract template) { this.Template=template; } /** * @return the templateId */ public String getTemplateId() { return TemplateId; } /** * @param templateId the templateId to set */ public void setTemplateId(String templateId) { this.TemplateId=templateId; } }
|