Hibernate配置映射文件问题

z420669202 2013-10-21 04:39:18
数据库是mysql:
create table employee(
id int primary key auto_increment not null,
name varchar(20) not null,
email varchar(50) not null);

辅助类:
public class Employee {
private int id;
private String name;
private String email;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
}

总配置文件hibernate.cfg.xml:
<hibernate-configuration>
<session-factory>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost:8887/zmhy</property>
<property name="connection.username">root</property>
<property name="connection.password">zjinxi123</property>
<property name="show_sql">true</property>
<mapping resource="com/hibernate/domain/Employee.hbm.xml" />
</session-factory>
</hibernate-configuration>
端口无问题 用ibatis的时候能连上

映射文件Employee.hbm.xml:
<hibernate-mapping package="com.hibernate.domain">
<class name="Employee" table="employee">
<id name="id" type="int" column="id">
<generator class="native" ></generator>
</id>
<property name="name" type="java.lang.String">
<column name="name" not-null="false"></column>
</property>
<property name="email" type="java.lang.String">
<column name="email" not-null="false"></column>
</property>
</class>
</hibernate-mapping>
主键的generator属性不会配 问题是不是在这?

小弟今天刚学hibernate 搞了一天都失败了 求大神帮忙看看!
...全文
16376 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
叨乐 2016-03-10
  • 打赏
  • 举报
回复
您好,大侠,我想问一下你说的点是哪儿的点呀?我也遇到了一毛一样的问题啊啊啊啊?
z420669202 2013-10-21
  • 打赏
  • 举报
回复
终于发现问题了 原来是dtd地址前面少个点 坑爹呢
z420669202 2013-10-21
  • 打赏
  • 举报
回复
测试类: public static void main(String[] args) { Configuration cg=new Configuration().configure(); SessionFactory sessionFactory=cg.buildSessionFactory(); Session session=sessionFactory.openSession(); Transaction transaction=session.beginTransaction(); //具体操作 添加一个雇员 Employee employee = new Employee(); employee.setName("xiaofei"); employee.setEmail("zimudaguoguo@qq.com"); session.save(employee); //事务提交 transaction.commit(); session.close(); }
z420669202 2013-10-21
  • 打赏
  • 举报
回复
10 [main] INFO org.hibernate.cfg.Environment - Hibernate 3.3.1.GA 12 [main] INFO org.hibernate.cfg.Environment - hibernate.properties not found 15 [main] INFO org.hibernate.cfg.Environment - Bytecode provider name : javassist 18 [main] INFO org.hibernate.cfg.Environment - using JDK 1.4 java.sql.Timestamp handling 56 [main] INFO org.hibernate.cfg.Configuration - configuring from resource: /hibernate.cfg.xml 56 [main] INFO org.hibernate.cfg.Configuration - Configuration resource: /hibernate.cfg.xml 121 [main] INFO org.hibernate.cfg.Configuration - Reading mappings from resource : com/hibernate/domain/Employee.hbm.xml Exception in thread "main" org.hibernate.InvalidMappingException: Could not parse mapping document from resource com/hibernate/domain/Employee.hbm.xml at org.hibernate.cfg.Configuration.addResource(Configuration.java:602) at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1621) at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1589) at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1568) at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1542) at org.hibernate.cfg.Configuration.configure(Configuration.java:1462) at org.hibernate.cfg.Configuration.configure(Configuration.java:1448) at com.hibernate.view.Test.main(Test.java:14) Caused by: org.hibernate.InvalidMappingException: Could not parse mapping document from input stream at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:541) at org.hibernate.cfg.Configuration.addResource(Configuration.java:599) ... 7 more Caused by: org.dom4j.DocumentException: Connection timed out: connect Nested exception: Connection timed out: connect at org.dom4j.io.SAXReader.read(SAXReader.java:484) at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:532) ... 8 more 抛出的异常是映射配置文件没映射好 请问问题出在哪?

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧