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

本文介绍了一位初学者在使用Hibernate4过程中遇到的配置错误问题,详细解释了错误发生的原因及正确的配置方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

初学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);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值