hibernate 异常求解决

11:07:37,716 INFO Version:37 - Hibernate Commons Annotations 3.2.0.Final
11:07:37,723 INFO Environment:603 - Hibernate 3.6.10.Final
11:07:37,724 INFO Environment:636 - hibernate.properties not found
11:07:37,727 INFO Environment:814 - Bytecode provider name : javassist
11:07:37,729 INFO Environment:695 - using JDK 1.4 java.sql.Timestamp handling
11:07:37,771 INFO Configuration:2156 - configuring from resource: /hibernate.cfg.xml
11:07:37,771 INFO Configuration:2175 - Configuration resource: /hibernate.cfg.xml
11:07:37,826 INFO Configuration:789 - Reading mappings from resource : cn/wyz/domain/Customer.hbm.xml
11:07:37,891 INFO Configuration:2297 - Configured SessionFactory: null
11:07:37,923 INFO HbmBinder:353 - Mapping class: cn.wyz.domain.Customer -> customer
11:07:37,936 INFO Configuration:1676 - Hibernate Validator not found: ignoring
11:07:37,940 INFO HibernateSearchEventListenerRegister:75 - Unable to find org.hibernate.search.event.FullTextIndexEventListener on the classpath. Hibernate Search is not enabled.

Customer.hbm.xml文件
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">

<id name="id" column="id" type="int">
    <generator class="native"></generator>
</id>
<property name="name" column="name" type="java.long.String"></property>
<property name="age" column="age" type="int"></property>
<property name="city" column="city" type="java.long.String"></property>
</class>

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">


com.mysql.jdbc.Driver
jdbc:mysql:///customer
wyz
123456

    <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>

    <property name="hibernate.show_sql">true</property>
    <property name="hibernate.format_sql">true</property>
    <property name="hibernate.hbm2ddl.auto">update</property>

    <mapping resource="cn/wyz/domain/Customer.hbm.xml"/>


</session-factory>  

测试类
public class HibernateTest1 {
@Test
public void testAdd()
{
// 实例化配置对象,加载配置文件 hibernate.cfg.xml
Configuration configuration = new Configuration().configure();
// 创建会话连接工厂
SessionFactory sessionFactory = configuration.buildSessionFactory();
// 创建会话
Session session = sessionFactory.openSession();
// 开启事务
Transaction transaction = session.beginTransaction();
// 这里可以编写hibernate操作代码逻辑
Customer customer=new Customer();
customer.setName("张三");
customer.setAge(18);
customer.setCity("河北");
session.save(customer);

    // 提交事务,释放资源      
    transaction.commit();
    session.close();
    sessionFactory.close();

}

}

1个回答

hibernate.properties not found 有不是日志报错的提示么

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐