Solutions
Do not bring your own hibernate package to download Hibernate package Import
Recently this error has occurred
2015-5-10 12:24:16 org.hibernate.annotations.common.Version <clinit>
INFO:HCANN000001:Hibernate Commons Annotations {4.0.1.Final}
2015-5-10 12:24:16 org.hibernate.Version logversion
INFO:HHH000412:Hibernate Core {4.1.4.Final}
2015-5-10 12:24:16 org.hibernate.cfg.Environment <clinit>
INFO:HHH000206:hibernate.properties not found
2015-5-10 12:24:16 org.hibernate.cfg.Environment Buildbytecodeprovider
INFO:HHH000021:Bytecode provider Name:javassist
2015-5-10 12:24:16 org.hibernate.cfg.Configuration Configure
INFO:HHH000043:Configuring from resource:/hibernate.cfg.xml
2015-5-10 12:24:16 org.hibernate.cfg.Configuration Getconfigurationinputstream
INFO:HHH000040:Configuration resource:/hibernate.cfg.xml
2015-5-10 12:24:16 org.hibernate.cfg.Configuration AddResource
INFO:HHH000221:Reading Mappings from Resource:org/vo/usertable.hbm.xml
2015-5-10 12:24:16 org.hibernate.cfg.Configuration doconfigure
INFO:HHH000041:Configured Sessionfactory:null
2015-5-10 12:24:16 Org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl Configure
INFO:HHH000402:Using Hibernate built-in connection pool (not for production use!)
2015-5-10 12:24:16 Org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl Configure
INFO:HHH000115:Hibernate Connection Pool Size:20
2015-5-10 12:24:16 Org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl Configure
INFO:HHH000006:Autocommit Mode:false
2015-5-10 12:24:16 Org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl Configure
INFO:HHH000401:using driver [Com.microsoft.sqlserver.jdbc.SQLServerDriver] at URL [jdbc:sqlserver://localhost:1433 ;D Atabasename=test9_4]
2015-5-10 12:24:16 Org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl Configure
INFO:HHH000046:Connection properties: {user=sa, password=****}
2015-5-10 12:24:17 Org.hibernate.dialect.Dialect <init>
INFO:HHH000400:Using Dialect:org.hibernate.dialect.SQLServerDialect
2015-5-10 12:24:17 Org.hibernate.engine.transaction.internal.TransactionFactoryInitiator Initiateservice
INFO:HHH000399:Using default transaction strategy (direct JDBC transactions)
2015-5-10 12:24:17 org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory <init>
INFO:HHH000397:Using astquerytranslatorfactory
%%%% Error Creating sessionfactory%%%%
Java.lang.NullPointerException
At JAVA.LANG.CLASS.FORNAME0 (Native Method)
At Java.lang.Class.forName (class.java:247)
At Org.hibernate.annotations.common.util.ReflectHelper.classForName (reflecthelper.java:143)
At Org.hibernate.annotations.common.reflection.java.JavaReflectionManager.classForName ( javareflectionmanager.java:117)
At Org.hibernate.envers.configuration.RevisionInfoConfiguration.configure (revisioninfoconfiguration.java:262)
At Org.hibernate.envers.configuration.auditconfiguration.<init> (auditconfiguration.java:102)
At Org.hibernate.envers.configuration.AuditConfiguration.getFor (auditconfiguration.java:165)
At Org.hibernate.envers.event.EnversIntegrator.integrate (enversintegrator.java:64)
At Org.hibernate.internal.sessionfactoryimpl.<init> (sessionfactoryimpl.java:306)
At Org.hibernate.cfg.Configuration.buildSessionFactory (configuration.java:1744)
At Org.util.hibernatesessionfactory.<clinit> (hibernatesessionfactory.java:34)
At Org.test.HibernateTest.getCurrentSession (hibernatetest.java:26)
At Org.test.HibernateTest.main (hibernatetest.java:13)
2015-5-10 12:24:17 org.hibernate.cfg.Configuration Configure
INFO:HHH000043:Configuring from resource:/hibernate.cfg.xml
2015-5-10 12:24:17 org.hibernate.cfg.Configuration Getconfigurationinputstream
INFO:HHH000040:Configuration resource:/hibernate.cfg.xml
2015-5-10 12:24:17 org.hibernate.cfg.Configuration AddResource
INFO:HHH000221:Reading Mappings from Resource:org/vo/usertable.hbm.xml
2015-5-10 12:24:17 org.hibernate.cfg.Configuration doconfigure
INFO:HHH000041:Configured Sessionfactory:null
2015-5-10 12:24:17 Org.hibernate.cfg.configuration$mappingsimpl AddImport
INFO:HHH000071:Duplicate import:usertable-Usertable
%%%% Error Creating sessionfactory%%%%
Org.hibernate.InvalidMappingException:Could not parse mapping document from resource Org/vo/usertable.hbm.xml
At Org.hibernate.cfg.configuration$metadatasourcequeue.processhbmxml (configuration.java:3409)
At Org.hibernate.cfg.configuration$metadatasourcequeue.processhbmxmlqueue (configuration.java:3398)
At Org.hibernate.cfg.configuration$metadatasourcequeue.processmetadata (configuration.java:3386)
At Org.hibernate.cfg.Configuration.secondPassCompile (configuration.java:1341)
At Org.hibernate.cfg.Configuration.buildSessionFactory (configuration.java:1731)
At Org.util.HibernateSessionFactory.rebuildSessionFactory (hibernatesessionfactory.java:73)
At Org.util.HibernateSessionFactory.getSession (hibernatesessionfactory.java:55)
At Org.test.HibernateTest.getCurrentSession (hibernatetest.java:26)
At Org.test.HibernateTest.main (hibernatetest.java:13)
caused by:org.hibernate.DuplicateMappingException:Duplicate class/entity mapping usertable
At Org.hibernate.cfg.configuration$mappingsimpl.addclass (configuration.java:2574)
At Org.hibernate.cfg.HbmBinder.bindRoot (hbmbinder.java:172)
At Org.hibernate.cfg.configuration$metadatasourcequeue.processhbmxml (configuration.java:3406)
... 8 more
Exception in thread "main" java.lang.NullPointerException
At Org.test.HibernateTest.saveUser (hibernatetest.java:38)
At Org.test.HibernateTest.main (hibernatetest.java:14)
Bad call for Class package by classmate
I originally called Hibernate 4.1 Core Library and Hibernate 4.1 Advanced support Librarys
This is from MyEclipse 10.7.
Later downloaded the Hibernate-release-4.3.9.final official website of this
By introducing this
Copy all the required jar packages under C:\Users\Administrator\Desktop\hibernate-release-4.3.9.Final\lib\required under the compression package
And then
Finally introduced into the lower class package unified together
That's how the official hibernate version is introduced.
Then run the result to run
The operation results are as follows
2015-5-10 12:34:00 Org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit>
INFO:HCANN000001:Hibernate Commons Annotations {4.0.5.Final}
2015-5-10 12:34:00 org.hibernate.Version logversion
INFO:HHH000412:Hibernate Core {4.3.9.Final}
2015-5-10 12:34:00 org.hibernate.cfg.Environment <clinit>
INFO:HHH000206:hibernate.properties not found
2015-5-10 12:34:00 org.hibernate.cfg.Environment Buildbytecodeprovider
INFO:HHH000021:Bytecode provider Name:javassist
2015-5-10 12:34:00 org.hibernate.cfg.Configuration Configure
INFO:HHH000043:Configuring from resource:/hibernate.cfg.xml
2015-5-10 12:34:00 org.hibernate.cfg.Configuration Getconfigurationinputstream
INFO:HHH000040:Configuration resource:/hibernate.cfg.xml
2015-5-10 12:34:00 org.hibernate.cfg.Configuration AddResource
INFO:HHH000221:Reading Mappings from Resource:org/vo/usertable.hbm.xml
2015-5-10 12:34:00 org.hibernate.cfg.Configuration doconfigure
INFO:HHH000041:Configured Sessionfactory:null
2015-5-10 12:34:00 Org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl Configure
WARN:HHH000402:Using Hibernate built-in connection pool (not for production use!)
2015-5-10 12:34:00 Org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl Buildcreator
INFO:HHH000401:using driver [Com.microsoft.sqlserver.jdbc.SQLServerDriver] at URL [jdbc:sqlserver://localhost:1433; Databasename=test9_4]
2015-5-10 12:34:00 Org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl Buildcreator
INFO:HHH000046:Connection properties: {user=sa, password=****}
2015-5-10 12:34:00 Org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl Buildcreator
INFO:HHH000006:Autocommit Mode:false
2015-5-10 12:34:00 Org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl Configure
INFO:HHH000115:Hibernate Connection Pool size:20 (min=1)
2015-5-10 12:34:01 Org.hibernate.dialect.Dialect <init>
INFO:HHH000400:Using Dialect:org.hibernate.dialect.SQLServerDialect
2015-5-10 12:34:01 Org.hibernate.engine.transaction.internal.TransactionFactoryInitiator Initiateservice
INFO:HHH000399:Using default transaction strategy (direct JDBC transactions)
2015-5-10 12:34:01 org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory <init>
INFO:HHH000397:Using astquerytranslatorfactory
2015-5-10 12:34:02 Org.hibernate.tool.hbm2ddl.SchemaUpdate Execute
INFO:HHH000228:Running HBM2DDL Schema Update
2015-5-10 12:34:02 Org.hibernate.tool.hbm2ddl.SchemaUpdate Execute
INFO:HHH000102:Fetching Database Metadata
2015-5-10 12:34:02 Org.hibernate.tool.hbm2ddl.SchemaUpdate Execute
INFO:HHH000396:Updating schema
2015-5-10 12:34:02 Org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO:HHH000261:Table found:Test9_4.dbo.userTable
2015-5-10 12:34:02 Org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO:HHH000037:Columns: [ID, username, password]
2015-5-10 12:34:02 Org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO:HHH000108:Foreign keys: []
2015-5-10 12:34:02 Org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO:HHH000126:Indexes: [Pk_usertable]
2015-5-10 12:34:02 Org.hibernate.tool.hbm2ddl.SchemaUpdate Execute
INFO:HHH000232:Schema Update Complete
Database classes
So the data is plugged in.
Test should write like this.
Package Org.test;import Java.util.*;import Org.hibernate.query;import org.hibernate.session;import Org.hibernate.sessionfactory;import Org.hibernate.transaction;import Org.hibernate.cfg.configuration;import Org.util.hibernatesessionfactory;//import Org.vo.usertale;//import Org.vo.usertable;public class HibernateTest { Public Session session;public static void Main (string[] args) {//hibernatetest ht = new Hibernatetest ();//Create Class object//ht.getcu Rrentsession ();//Get the Session object configuration Cfg=new configuration (); Sessionfactory sessionfactory=cfg.configure (). Buildsessionfactory (); Session session=sessionfactory.opensession (); Transaction ts = session.begintransaction (); Map user = new HashMap (), User.put ("username", "Yabber"), User.put ("Password", "123456"), Session.save (" Org.vo.UserTable ", user); Ts.commit ();//ht.saveuser ();//ht.saveuser ();//Insert a record//ht.updateuser (); Modify the record//ht.queryuser ();//View Database Results//ht.deleteuser (); Delete the record//system.out.println ("Results ====== after deleting the Record");//ht.queryuseR ();//View Database Results//ht.closesession (); Close session}//Get session method public void Getcurrentsession () {//Call Hibernatesessionfactory GetSession method to create session Object session = Hibernatesessionfactory.getsession ();} Close Session method public void CloseSession () {if (session!=null) {hibernatesessionfactory.closesession ();//Close session}}// Insert a record method public void Saveuser () {//Save a Usertable object transaction ts = Session.begintransaction (); Map user = new HashMap (), User.put ("username", "Yabber"), User.put ("Password", "123456"), Session.save (" Org.vo.UserTable ", user); Ts.commit ();} Modify this record method public void UpdateUser () {//update a Usertable object transaction ts = Session.begintransaction (); Map user = new HashMap (), user = (MAP) session.get ("org.vo.UserTable", 18);//get record user.put with ID 18 ("Password", "654321"); Session.update ("org.vo.UserTable", user); Ts.commit ();} Query database result method public void Queryuser () {Query query = Session.createquery ("from usertable"); Query record list = Query.list (); for (int i=0;i<list.size (); i++) {Map user = (map) list.get (i); System.out.println (User.get ("username")); System.out.println (User.get ("password"));}} Delete the record method public void DeleteUser () {Transaction ts = session.begintransaction (); Map user = new HashMap (), user = (MAP) session.get ("Org.vo.UserTable"), Session.delete ("org.vo.UserTable", user); Ts.commit ();}}UserTable.hbm.xml
<?xml version= "1.0" encoding= "Utf-8"? ><! DOCTYPE hibernate-mapping Public "-//hibernate/hibernate mapping DTD 3.0//en" "http://www.hibernate.org/dtd/ Hibernate-mapping-3.0.dtd "><!-- mapping file autogenerated by MyEclipse persistence tools-->< hibernate-mapping> <class entity-name= "org.vo.UserTable" table= "usertable" > <id name= "id" column= "id" type= "integer" > <generator class= "Identity"/> </id> <property name= " Username "type=" string "column=" username "/> <property name=" password "type=" string "column=" password "/ > </class>
Hibernate.hbm.xml<?xml version= ' 1.0 ' encoding= ' UTF-8 '? ><! DOCTYPE hibernate-configuration Public "-//hibernate/hibernate configuration DTD 3.0//en" "Http://www.hi Bernate.org/dtd/hibernate-configuration-3.0.dtd "><!--Generated by MyEclipse hibernate Tools. -->
Dynamic classes are map mappings rather than Pojo mappingsAbout the article describing map mappings
1 http://blog.csdn.net/meng2602956882/article/details/22914493
2 http://www.360doc.com/content/14/0329/19/281812_364737677.shtml
3 http://blog.csdn.net/opnmzxcvb/article/details/4785569
exception Dynamic model of Hibernate