用HIBERNATE遇到 duplicate import的问题

yphui18 2005-10-26 01:41:20
package com;
import java.io.File;

import net.sf.hibernate.HibernateException;
import net.sf.hibernate.Session;
import net.sf.hibernate.SessionFactory;
import net.sf.hibernate.cfg.Configuration;

public class HibernateUtil {
// private static Log log = LogFactory.getLog(HibernateUtil.class);
public static SessionFactory sessionFactory;
static{
try{
File file = new File("E:\\Java Dev\\try\\JavaSource\\hibernate.cfg.xml");
Configuration config = new Configuration().configure(file);
sessionFactory=config.configure().buildSessionFactory();
}catch(Exception e){
//log.error("Init sessionFactory failed!",e);
System.out.println("Init sessionFactory failed!" + e);
}
}
public void deleteall() throws HibernateException
{
Session s=sessionFactory.openSession();
if(s==null)
{
System.out.println("s is null");
}
else
{
System.out.println("s is not null");
}

net.sf.hibernate.Transaction tx=null;
try
{
tx=s.beginTransaction();
if(tx==null)
{
System.out.println("tx is null");
}
else
{
System.out.println("tx is not null");
}
Login loginer=new Login();
// loginer.setUsername(1);
loginer.setPwd("dsf");
s.save(loginer);

// s.delete("from login");
tx.commit();

}
catch(Exception ee)
{
if(tx!=null)
{

tx.rollback();
}
System.out.println(ee);

}
finally
{
s.close();
}
}


public static void main(String[] args) throws Exception{
new HibernateUtil().deleteall();
}
}
错误信息如下:
Could not compile the mapping document
net.sf.hibernate.MappingException: duplicate import: Login
at net.sf.hibernate.cfg.Mappings.addImport(Mappings.java:85)
at net.sf.hibernate.cfg.Binder.bindClass(Binder.java:127)
at net.sf.hibernate.cfg.Binder.bindRootClass(Binder.java:222)
at net.sf.hibernate.cfg.Binder.bindRoot(Binder.java:1257)
at net.sf.hibernate.cfg.Configuration.add(Configuration.java:252)
at net.sf.hibernate.cfg.Configuration.addInputStream(Configuration.java:288)
at net.sf.hibernate.cfg.Configuration.addResource(Configuration.java:336)
at net.sf.hibernate.cfg.Configuration.doConfigure(Configuration.java:1018)
at net.sf.hibernate.cfg.Configuration.doConfigure(Configuration.java:974)
at net.sf.hibernate.cfg.Configuration.configure(Configuration.java:902)
at net.sf.hibernate.cfg.Configuration.configure(Configuration.java:888)
at com.HibernateUtil.<clinit>(HibernateUtil.java:34)
Init sessionFactory failed!net.sf.hibernate.MappingException: Error reading resource: Login.hbm
java.lang.NullPointerException
at com.HibernateUtil.deleteall(HibernateUtil.java:46)
at com.HibernateUtil.main(HibernateUtil.java:96)
Exception in thread "main"
...全文
377 点赞 收藏 3
写回复
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
sgdb 2005-10-28
Configuration config = new Configuration().configure(file);
sessionFactory=config.configure().buildSessionFactory();

导入里次配置,当然要出问题了
回复
fbtdjs 2005-10-28
XML中是不是定义了两个Login
回复
YuLimin 2005-10-27
hibernate.cfg.xml文件内容放出来。

Login.hbm是不是重复了?
回复
发动态
发帖子
Java EE
创建于2007-09-28

6.6w+

社区成员

J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
申请成为版主
社区公告
暂无公告