0

嗨,我在 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() 收到此错误。请帮忙。我是新手,从基础开始学习休眠。

4

1 回答 1

0

您应该使用会话对象检查您要保存的类。我遇到了同样的问题,通过代码后我发现我正在尝试持久化会话对象。所以我干脆去掉了这个缺陷,程序运行顺利

于 2017-08-25T18:51:37.550 回答