exception - org.hibernate.MappingException: Unknown entity when trying to save POJO -
i below error when invoke method save entity database.
error: org.aggu.sramam.exceptions.sramamexception - exception thrown: org.hibernate.mappingexception: unknown entity: org.aggu.sramam.pojo.sramasangham @ org.hibernate.internal.sessionfactoryimpl.getentitypersister(sessionfactoryimpl.java:1096) @ org.hibernate.internal.sessionimpl.getentitypersister(sessionimpl.java:1443
the pojo object there in package, , have below entry in hibernate-cfg.xml file
<hibernate-configuration> <!-- list out entities (i.e pojo linked db table) here --> <session-factory> <mapping class="org.aggu.sramam.pojo.sramasangham" /> </session-factory> </hibernate-configuration>
below entry in servlet-config.xml file, gives code base links
<!-- below base package sramam apps --> <context:component-scan base-package="org.aggu.sramam" />
what have missed here? have added @entity, @table, @id tags etc. in pojo object. there unqiue id column (primary key), have not written explicit code generate id automatically. problem?
okay. figured out myself. issue in servlet-context.xml file, had not given reference/link hibernate.cfg.xml. once given, error got resolved , records started getting inserted.
<beans:bean id="sessionfactory" class="org.springframework.orm.hibernate4.localsessionfactorybean"> <beans:property name="datasource" ref="datasource" /> <beans:property name="hibernateproperties"> <beans:props> <beans:prop key="hibernate.show_sql">true</beans:prop> <beans:prop key="hibernate.hbm2ddl.auto">create</beans:prop> <beans:prop key="hibernate.dialect">${jdbc.dialect}</beans:prop> </beans:props> </beans:property> **<!- line did trick --> <beans:property name="configlocation"> <beans:value>web-inf/classes/hibernate.cfg.xml</beans:value> </beans:property>** </beans:bean>
Comments
Post a Comment