Java Learning Note--hibernate Framework error collection and resolution

Source: Internet
Author: User

Error 1:mappingexception:unknown Entity Solution

Http://jingyan.baidu.com/article/e75aca8552761b142edac6cf.html

error 2:could not bind factory to JNDI

2006-07-23 23:14:53,796 [main] WARN org.hibernate.impl.SessionFactoryObjectFactory-Could not bind factory to JNDIjavax.naming.NoInitialContextException:Need to specifyclassname in environment or system property, or as a applet parameter, or in an application resource FILE:JAVA.NAMING.F Actory.initial at Javax.naming.spi.NamingManager.getInitialContext (Namingmanager.java:645) at Javax.naming.InitialContext.getDefaultInitCtx (Initialcontext.java:247) at Javax.naming.InitialContext.getURLOrDefaultInitCtx (Initialcontext.java:284) at Javax.naming.InitialContext.getNameParser (Initialcontext.java:439) at Org.hibernate.util.NamingHelper.bind (Naminghelper.java:52) at Org.hibernate.impl.SessionFactoryObjectFactory.addInstance (Sessionfactoryobjectfactory.java:90) at Org.hibernate.impl.SessionFactoryImpl.<init> (sessionfactoryimpl.java:291) at Org.hibernate.cfg.Configuration.buildSessionFactory (Configuration.java:1176) at Reene.study.hibernate.test.TestMain.main (Testmain.java:19)

find the following online:

(3) Error: Could not bind factory to JNDI
This error is a profile issue, if hibernate config file has session_factory_name this variable, <session-factory name= "foo" > Attempts to bind a sessionfactory instance to Jndi on the name of Foo, while some application container do not support jndi bindings. get rid of this variable.

Solve the problem

The reference code should also be modified:
Roughly changed to this:

New== session.begintransaction ();

Error 3:entity class not found:

Org.hibernate.MappingException:entity class not Found:customer at Org.hibernate.mapping.PersistentClass.getMappedClass (persistentclass.java:128) at Org.hibernate.tuple.PropertyFactory.getGetter (propertyfactory.java:390) at Org.hibernate.tuple.PropertyFactory.buildIdentifierProperty (propertyfactory.java:75) at Org.hibernate.tuple.entity.EntityMetamodel.<Init>(entitymetamodel.java:145) at Org.hibernate.persister.entity.AbstractEntityPersister.<Init>(abstractentitypersister.java:505) at Org.hibernate.persister.entity.SingleTableEntityPersister.<Init>(singletableentitypersister.java:144) at Sun.reflect.NativeConstructorAccessorImpl.newInstance0 (Native Method ) at Sun.reflect.NativeConstructorAccessorImpl.newInstance (nativeconstructoraccessorimpl.java:57) at Sun.reflect.DelegatingConstructorAccessorImpl.newInstance (delegatingconstructoraccessorimpl.java:45) at Java.lang.reflect.Constructor.newInstance (constructor.java:526) at Org.hibernate.persister.internal.PersisterFactoryImpl.create (persisterfactoryimpl.java:163) at Org.hibernate.persister.internal.PersisterFactoryImpl.createEntityPersister (persisterfactoryimpl.java:135) at Org.hibernate.internal.SessionFactoryImpl.<Init>(sessionfactoryimpl.java:386) at Org.hibernate.cfg.Configuration.buildSessionFactory (configuration.java:1744) at Org.hibernate.cfg.Configuration.buildSessionFactory (configuration.java:1782) at Com.session.Test.main (Test.java    : Caused By:java.lang.ClassNotFoundException:Customer at Java.net.urlclassloader$1.run (urlclassloader.java:366) At Java.net.urlclassloader$1.run (urlclassloader.java:355) at java.security.AccessController.doPrivileged (Native Method) at Java.net.URLClassLoader.findClass (urlclassloader.java:354) at Java.lang.ClassLoader.loadClass ( classloader.java:425) at Sun.misc.launcher$appclassloader.loadclass (launcher.java:308) at Java.lang.ClassLoader.loadClass (classloader.java:358) at JAVA.LANG.CLASS.FORNAME0 (Native Method) at Java.lang.Class . forname (class.java:190) at Org.hibernate.internal.util.ReflectHelper.classForName (reflecthelper.java:192) at Org.hibernate.mapping.PersistentClass.getMappedClass (persistentclass.java:125) ...More 

Modify Customer.hbm.xml

Original class name

    <classname= "Customer"Table= "CUSTOMER">        <IDname= "id"column= "CID"type= "Java.lang.Integer">            <Generatorclass= "Increment" />        </ID>        < Propertyname= "username"column= "USERNAME"type= "Java.lang.String"/>        < Propertyname= "Password"column= "PASSWORD"type= "Java.lang.String"/>    </class>

Revision changed to

    <classname= "Com.session.Customer"Table= "CUSTOMER">        <IDname= "id"column= "CID"type= "Java.lang.Integer">            <Generatorclass= "Increment" />        </ID>        < Propertyname= "username"column= "USERNAME"type= "Java.lang.String"/>        < Propertyname= "Password"column= "PASSWORD"type= "Java.lang.String"/>    </class>

Error 4:attribute "column" must is declared for element type ' property ' workaround

I wrote the Xxx.hbm.xml file error:
Attribute "column" must is declared for element type ' property '
This mistake was made because I The hibernate.cfg.xml file header is copied directly to the Xxx.hbm.xml (Customer.hbm.xml)

Hibernate.cfg.xml's file header:

<? xmlversion= ' 1.0 ' encoding= ' UTF-8 ' ?> <! DOCTYPE hibernate-configuration Public         "-//hibernate/hibernate configuration DTD 3.0//en"         "http// Hibernate.sourceforge.net/hibernate-configuration-3.0.dtd ">

This should be changed to mapping's head file.

Customer.hbm.xml's file header

<? xmlversion= "1.0" encoding= "UTF-8 " ?> <! doctypehibernate-mapping public         "-//hibernate/hibernate mapping DTD 3.0//en"         "/HTTP/ Hibernate.sourceforge.net/hibernate-mapping-3.0.dtd ">

Then you can write your own map in it.

Error 5:not found while looking for property error

Not found while looking on property error
caused By:org.hibernate.MappingException:com.session.Customer not found and looking for Property:id

The configuration file is as follows

<?XML version= "1.0" encoding= "Utf-8"?><!DOCTYPE hibernate-mapping Public "-//hibernate/hibernate mapping DTD 3.0//en" "Http://hibernate.source Forge.net/hibernate-mapping-3.0.dtd "><hibernate-mapping>    <classname= "Com.session.Customer"Table= "CUSTOMER">        <IDname= "id"column= "CID">            <Generatorclass= "Increment" />        </ID>        < Propertyname= "username"column= "USERNAME"/>        < Propertyname= "Password"column= "PASSWORD"/>    </class></hibernate-mapping>

There seems to be no problem finding your own configuration. Search on the Internet for reasons: Links

Add the attribute to each value in the method. Modify the following:

<?XML version= "1.0" encoding= "Utf-8"?><!DOCTYPE hibernate-mapping Public "-//hibernate/hibernate mapping DTD 3.0//en" "Http://hibernate.source Forge.net/hibernate-mapping-3.0.dtd "><hibernate-mapping>    <classname= "Com.session.Customer"Table= "CUSTOMER">        <IDname= "id"column= "CID"type= "Java.lang.Integer">            <Generatorclass= "Increment" />        </ID>        < Propertyname= "username"column= "USERNAME"type= "Java.lang.String"/>        < Propertyname= "Password"column= "PASSWORD"type= "Java.lang.String"/>    </class></hibernate-mapping>

Java Learning Note--hibernate Framework error collection and resolution

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.