繁体   English   中英

应用程序中的Hibernate .hbm.xml文件路径?

[英]Hibernate .hbm.xml files path in application?

我从文档中获得了这行代码

 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();
    }

这里我没有给Hibernate提供Event.hbm.xml文件的路径,我怀疑hibernate所指的是哪个目录找到Event.hbm.xml来映射Event.java实体类? 现在我将Event和Event.hbm.xml文件保存在同一个包中。

通常, Event.hbm.xml应该在与Event.class文件相同的包中的运行时类路径中结束。 /WEB-INF/classes/foo/bar/这样的东西,如果它是一个Web应用程序。 话虽如此,将它放在src文件夹中可能没问题,因为您的IDE应该在构建期间自动将其放在/WEB-INF/classes/foo/bar中。

在你的hibernate-configuration xml中,你通常应该按如下方式定义你的其他hbm文件;

     <mapping resource="com/domain/Event.hbm.xml"/>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM