一.entity找不到问题一般出现在hibernate.cfg.xml文件中
二.主键自增没设置
Exception in thread "main" org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned before calling save(): com.lrq.entity.Project
解决方案:在Project.hbm.xml里面配置
三.Transation通过get方式得到而不是begin,会显示没有开启事务
Exception in thread "main" org.hibernate.TransactionException: Transaction not successfully started
解决方案:
Transaction tx=session.beginTransaction();
四.没有注册用户名和密码错误
Exception in thread "main" java.lang.ExceptionInInitializerError
at com.lrq.test.TestOneToOne.main(TestOneToOne.java:15)
Caused by: org.hibernate.exception.JDBCConnectionException: Error calling Driver#connect
。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1930)
at com.lrq.util.SessionFactoryUtil.
... 1 more
Caused by: java.sql.SQLException: Access denied for user ''@'localhost' (using password: NO)
解决方案:
五.Xml设置关联关系错误
Exception in thread "main" java.lang.ExceptionInInitializerError
at com.lrq.test.TestOneToOne.main(TestOneToOne.java:15)
Caused by: org.hibernate.MappingException: property-ref [user] not found on entity [com.lrq.entity.Weapon]
at org.hibernate.mapping.PersistentClass.getReferencedProperty(PersistentClass.java:385)
at org.hibernate.cfg.Configuration.originalSecondPassCompile(Configuration.java:1724)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1426)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1846)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1930)
at com.lrq.util.SessionFactoryUtil.
... 1 more
Caused by: org.hibernate.MappingException: property [user] not found on entity [com.lrq.entity.Weapon]
at org.hibernate.mapping.PersistentClass.getRecursiveProperty(PersistentClass.java:442)
at org.hibernate.mapping.PersistentClass.getReferencedProperty(PersistentClass.java:382)
... 6 more
解决方案:
六.属性Id没有默认值,一般是表里面没设置自增
Exception in thread "main" org.hibernate.exception.GenericJDBCException: could not execute statement
aorg.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:54)
。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
Caused by: java.sql.SQLException: Field 'weaponId' doesn't have a default value