发布于 2015-05-24 14:56:24 | 277 次阅读 | 评论: 1 | 来源: PHPERZ
Hibernate 开源对象关系映射框架 ORM
Hibernate是一个开放源代码的对象关系映射框架,它对JDBC进行了非常轻量级的对象封装,使得Java程序员可以随心所欲的使用对象编程思维来操纵数据库。 Hibernate可以应用在任何使用JDBC的场合,既可以在Java的客户端程序使用,也可以在Servlet/JSP的Web应用中使用,最具革命意义的是,Hibernate可以在应用EJB的J2EE架构中取代CMP,完成数据持久化的重任。
配置文件常常遇到的错误:
这个是hibernate.cfg.xml映射文件配置没有找到! 必须写相对于classpath的全部路径;
<mapping
resource="com/itcream/entity/Users.hbm.xml">
</mapping>
这个是数据库链接异常链接路径有误
<property name="connection.url">jdbc:oracle:thin:@10.0.0.1:1521:orcl
</property>
需要修改能连接的路径
<property
name="connection.url">jdbc:oracle:thin:@localhost:1521:orcl</property>
Exception in thread "main" java.lang.NullPointerException
<property name="dialect">org.hibernate.dialect.Oracle9gDialect</property>
没有这个Oracle9g 乱搞
可以改成Oracle9
报错:281 [main] INFO org.hibernate.cfg.HbmBinder - Mapping class:com.itcream.entity.Users -> Users
297 [main] INFO org.hibernate.cfg.Configuration - ConfiguredSessionFactory: null
Exception in thread "main" java.lang.NullPointerException
修改把long--->lang
<class name="Users">
626 [main] INFO org.hibernate.cfg.SettingsFactory - Defaultentity-mode: pojo
626 [main] INFO org.hibernate.cfg.SettingsFactory - Named querychecking : enabled
673 [main] INFO org.hibernate.impl.SessionFactoryImpl - buildingsession factory
Exception in thread "main" java.lang.NullPointerException
修改把<class name="com.itcream.entity.Users">
6
7
实体配置文件中属性 没有和数据库中对应。
796 [main] INFO org.hibernate.cfg.Configuration - configuring fromresource: /hibernate.cfg.xml
796 [main] INFO org.hibernate.cfg.Configuration - Configurationresource: /hibernate.cfg.xml
Exception in thread "main" java.lang.NullPointerException
conf=new Configuration().configure("这个路径必须写对");
配置文件路径必须写对 必须写相对于classpath的全部路径;
严重: Couldnot synchronize database state with session
org.hibernate.TransientObjectException: object references an unsaved transient instance - save thetransient instance before flushing: com.chenfei.entity.Street
错误原因:
必须写对
否则就会报这个错误;
689 [main] INFOorg.hibernate.cfg.SettingsFactory - Echoing all SQL to stdout
690 [main] INFOorg.hibernate.cfg.SettingsFactory - Statistics: disabled
690 [main] INFOorg.hibernate.cfg.SettingsFactory - Deleted entity synthetic identifierrollback: disabled
690 [main] INFOorg.hibernate.cfg.SettingsFactory - Default entity-mode: pojo
690 [main] INFOorg.hibernate.cfg.SettingsFactory - Named query checking : enabled
731 [main] INFOorg.hibernate.impl.SessionFactoryImpl - building session factory
Exception in thread"main" java.lang.NullPointerException
atcom.itcream.dao.impl.OnetomanyDistrctDaoImpl.save(OnetomanyDistrctDaoImpl.java:35)
at com.itcream.test.test.addC(test.java:164)
atcom.itcream.test.test.main(test.java:50)
这里的错误是:
需要修改正确的对象名称
改正