Hibernate 4出现的Could not parse mapping document from resource,Duplicate class/entity mapping

来源:互联网 发布:端口映射软件 编辑:程序博客网 时间:2024/06/05 04:45

初学Hibernate,用的又是最新版本,在运行类似HelloWord程序时出现了Could not parse mapping document from resource...在网上寻找原因,都说出现这种原因一般是配置文件出错,然后我就仔仔细细的查看了配置文件,就是没找出错误,接着我查看了引起异常的地方Duplicate class/entity mapping ,然后我有查看类中的方法,发现我在创建SessionFacotry用错了方法,由于当初创建SessionFacotry时对Hibernate 4 新的创建方法不是很懂,直接复制了网上的方法,导致出现错误,错误代码如下:

Configuration cfg = new Configuration().configure();

StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder().applySettings(cfg.getProperties());
StandardServiceRegistryImpl registryImpl = (StandardServiceRegistryImpl) builder.build();
SessionFactory sf = cfg.configure().buildSessionFactory(registryImpl);

解决方案,将上述代码改为SessionFactory sf = cfg.buildSessionFactory(registryImpl);

0 0
原创粉丝点击