I am having this lines of code from documentation
private void createAndStoreEvent(String title, Date theDate) {
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
Event theEvent = new Event();
theEvent.setTitle(title);
theEvent.setDate(theDate);
session.save(theEvent);
session.getTransaction().commit();
}
Here I am not giving path of Event.hbm.xml file to Hibernate and my doubt is which directory the hibernate refers to find Event.hbm.xml for mapping of Event.java entity class?. Now i am saving Event and Event.hbm.xml file in same package.
Normally, Event.hbm.xml
should end up in the runtime classpath in the same package as the Event.class
file. Something like /WEB-INF/classes/foo/bar/
if it's a Web application. That being said, putting it in the src
folder might be ok since your IDE
should automatically put it in the /WEB-INF/classes/foo/bar
during the build.
在你的hibernate-configuration xml中,你通常应该按如下方式定义你的其他hbm文件;
<mapping resource="com/domain/Event.hbm.xml"/>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.