您好,我在session.save()期间遇到错误。我不知道它为什么会来。我没有使用注释。我是从基础知识中学习的。请看下面的错误。我已花了2个多小时,但无法找到解决方案:
Aug 17, 2016 8:32:47 PM org.hibernate.impl.SessionFactoryObjectFactory addInstance
INFO: Not binding factory to JNDI, no JNDI name configured
Exception in thread "main" org.hibernate.MappingException: Unknown entity: org.hibernate.impl.SessionImpl
at org.hibernate.impl.SessionFactoryImpl.getEntityPersister(SessionFactoryImpl.java:548)
at org.hibernate.impl.SessionImpl.getEntityPersister(SessionImpl.java:1338)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:96)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:186)
at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:33)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:175)
at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:27)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
at org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:535)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:523)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:519)
at beans.Test.main(Test.java:24)
My Mapping file is :
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="beans.Student" table="Student" schema="mysql">
<id name="id" column="id"/>
<property name="name" column="name"/>
<property name="email" column="email"/>
<property name="marks" column="marks"/>
</class>
</hibernate-mapping>
My Hibernate-cfg-file :
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration SYSTEM
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">
com.mysql.jdbc.Driver
</property>
<property name="hibernate.connection.url">
jdbc:mysql://localhost:3306/mysql
</property>
<property name="hibernate.connection.username">
root
</property>
<property name="hibernate.connection.password">
?123
</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</property>
<property name="hibernate.hbm2ddl_auto">create</property>
<property name="hibernate.show_sql">true</property>
<mapping resource="resources/Student.hbm.xml"/>
</session-factory>
</hibernate-configuration>
我在session.save()收到此错误。请帮帮忙。我是新手,从基础学习hibernate。
答案 0 :(得分:0)
您应该使用会话对象检查您要尝试保存的班级。我遇到了同样的问题,经过代码我发现我试图坚持会话对象。所以我只是删除了这个漏洞并且程序运行顺利