当前位置: 代码迷 >> Java Web开发 >> 初学,生手求大神帮忙
  详细解决方案

初学,生手求大神帮忙

热度:5629   发布时间:2013-02-25 21:04:58.0
初学,新手求大神帮忙啊
hibernate.cfg.xml里面的代码
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
          "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
          "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<!-- Generated by MyEclipse Hibernate Tools.                   -->
<hibernate-configuration>

<session-factory>
<property name="dialect">
org.hibernate.dialect.SQLServerDialect
</property>
<property name="connection.url">
jdbc:sqlserver://localhost:1433
</property>
<property name="connection.username">sa</property>
<property name="connection.password">123</property>
<property name="connection.driver_class">
com.microsoft.sqlserver.jdbc.SQLServerDriver
</property>
<property name="myeclipse.connection.profile">House</property>
<property name="show_sql">true</property>
<mapping resource="cn/jbit/bean/Users.hbm.xml" />

</session-factory>

</hibernate-configuration>
Tes.t.java里面的代码
package cn.jbit.test;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;

import cn.jbit.bean.Users;

public class Test {

/**
 * @param args
 */
public static void main(String[] args)
{

/**
 * @param args
 */


Configuration conf = new Configuration().configure();
SessionFactory sf =conf.buildSessionFactory();
Session session = sf.openSession();
Transaction tx = session.beginTransaction();
Users users= new Users();

users.setName("zhangsan");
users.setPassword("12345");
users.setTelephone("123213");
users.setIsadmin("是");
users.setUsername("dfjdsj");
session.save(users);
tx.commit();
session.close();

}

}
一片惨红的代码
2013-1-23 10:02:25 org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {4.1.4.Final}
2013-1-23 10:02:25 org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
2013-1-23 10:02:25 org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
2013-1-23 10:02:25 org.hibernate.cfg.Configuration configure
INFO: HHH000043: Configuring from resource: /hibernate.cfg.xml
2013-1-23 10:02:25 org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: HHH000040: Configuration resource: /hibernate.cfg.xml
2013-1-23 10:02:25 org.hibernate.cfg.Configuration addResource
INFO: HHH000221: Reading mappings from resource: cn/jbit/bean/Users.hbm.xml
Exception in thread "main" org.hibernate.InvalidMappingException: Unable to read XML
at org.hibernate.internal.util.xml.MappingReader.readMappingDocument(MappingReader.java:109)
at org.hibernate.cfg.Configuration.add(Configuration.java:478)
  相关解决方案