i have 2 tables (users, vacations). created 2 file table.hbm.xml , code: table.hbm.xml
<?xml version="1.0" encoding="utf-8"?> <!doctype hibernate-mapping public "-//hibernate/hibernate mapping dtd 3.0//en" "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> <hibernate-mapping package="com.terafast.manager.model"> <class name="user" table="users"> <id name="id" column="user_id"> <generator class="native" /> </id> <property name="username" column="username" /> <property name="password" column="password" /> <property name="email" column="email" /> </class> <class name="vacation" table="vacations"> <id name="id" column="request_id"> <generator class="native" /> </id> <property name="who" column="user_id" /> <property name="when" column="start_date" /> <property name="reason" column="reason" /> <property name="duration" column="how_long" /> <property name="create" column="created_at" /> <property name="status" column="status" /> </class> </hibernate-mapping> hibernate.cfg.xml
<?xml version='1.0' encoding='utf-8'?> <!doctype hibernate-configuration public "-//hibernate/hibernate configuration dtd 3.0//en" "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"> <hibernate-configuration> <session-factory> <property name="dialect">org.hibernate.dialect.mysqldialect</property> <property name="show_sql">true</property> <mapping resource="com/terafast/manager/model/table.hbm.xml"/> </session-factory> </hibernate-configuration> vacation.hbm.xml (seperated)
<?xml version="1.0" encoding="utf-8"?> <!doctype hibernate-mapping public "-//hibernate/hibernate mapping dtd 3.0//en" "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> <hibernate-mapping package="com.terafast.manager.model"> <class name="vacation" table="vacations"> <id name="id" column="request_id"> <generator class="native" /> </id> <property name="who" column="user_id" /> <property name="when" column="start_date" /> <property name="reason" column="reason" /> <property name="duration" column="how_long" /> <property name="create" column="created_at" /> <property name="status" column="status" /> </class> </hibernate-mapping> my web application work 1 table (users). when add vacations on table.hbm.xml got error.
part of error severe: context initialization failed org.springframework.beans.factory.beancreationexception: error creating bean name 'sessionfactory' defined in servletcontext resource [/web-inf/spring/root-context.xml]: invocation of init method failed; nested exception org.hibernate.invalidmappingexception: not parse mapping document resource com/terafast/manager/model/table.hbm.xml @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.initializebean(abstractautowirecapablebeanfactory.java:1553) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.docreatebean(abstractautowirecapablebeanfactory.java:539) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.createbean(abstractautowirecapablebeanfactory.java:475) @ org.springframework.beans.factory.support.abstractbeanfactory$1.getobject(abstractbeanfactory.java:304) @ org.springframework.beans.factory.support.defaultsingletonbeanregistry.getsingleton(defaultsingletonbeanregistry.java:228) @ org.springframework.beans.factory.support.abstractbeanfactory.dogetbean(abstractbeanfactory.java:300) @ org.springframework.beans.factory.support.abstractbeanfactory.getbean(abstractbeanfactory.java:195) @ org.springframework.beans.factory.support.defaultlistablebeanfactory.preinstantiatesingletons(defaultlistablebeanfactory.java:684) @ org.springframework.context.support.abstractapplicationcontext.finishbeanfactoryinitialization(abstractapplicationcontext.java:760) @ org.springframework.context.support.abstractapplicationcontext.refresh(abstractapplicationcontext.java:482) @ org.springframework.web.context.contextloader.configureandrefreshwebapplicationcontext(contextloader.java:403) @ org.springframework.web.context.contextloader.initwebapplicationcontext(contextloader.java:306) @ org.springframework.web.context.contextloaderlistener.contextinitialized(contextloaderlistener.java:106) @ org.apache.catalina.core.standardcontext.listenerstart(standardcontext.java:4729) @ org.apache.catalina.core.standardcontext.startinternal(standardcontext.java:5167) @ org.apache.catalina.util.lifecyclebase.start(lifecyclebase.java:150) @ org.apache.catalina.core.containerbase$startchild.call(containerbase.java:1409) @ org.apache.catalina.core.containerbase$startchild.call(containerbase.java:1399) @ java.util.concurrent.futuretask.run(unknown source) @ java.util.concurrent.threadpoolexecutor.runworker(unknown source) @ java.util.concurrent.threadpoolexecutor$worker.run(unknown source) @ java.lang.thread.run(unknown source) could explain this?
<?xml version="1.0" encoding="utf-8"?> <!doctype hibernate-configuration system "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"> <hibernate-configuration> <session-factory> <property name="hibernate.dialect"> org.hibernate.dialect.mysqldialect </property> <property name="hibernate.connection.driver_class"> com.mysql.jdbc.driver </property> <!-- assume test database name --> <property name="hibernate.connection.url"> jdbc:mysql://localhost:3306/{your-db-name} </property> <property name="hibernate.connection.username"> {user-name} </property> <property name="hibernate.connection.password"> {password} </property> <!-- list of xml mapping files --> <mapping resource="{your-first-table}.hbm.xml"/> <mapping resource="{your-second-table}.hbm.xml"/> </session-factory> </hibernate-configuration>
Comments
Post a Comment