Web Engineering uses hibernate alone (for testing and getting started with hibernate)

Source: Internet
Author: User
Tags deprecated

1 First download Hibernate package address: http://hibernate.org/orm/

2 Create a new Web project, add Hibernate lib Reference package (the first step of the extracted files in the Lib folder under the required folder under the directory of the jar to copy to the Web project Webroot Web-inf Lib)

3 File structure

The 4 test class is used as a testing effect: code:

 PackageCom.sinosoft;Importorg.hibernate.Session;Importorg.hibernate.SessionFactory;Importorg.hibernate.Transaction;Importorg.hibernate.cfg.Configuration; Public classTest { Public Static voidMain (string[] args) {Configuration cfg=NewConfiguration (); Cfg.configure ("Hibernate.cfg.xml"); @SuppressWarnings ("Deprecation") sessionfactory SF=cfg.buildsessionfactory (); Session Session=sf.opensession (); Transaction TX=session.begintransaction (); Person Person=NewPerson (); Person.setname ("Lxy");    Session.save (person);    Tx.commit ();    Session.close ();    Sf.close (); }}

Run the test class in Java application to detect the effect.

5 Note: *<property name = "dialect" >org.hibernate.dialect.OracleDialect</property> this statement must be corresponding to the jar package driver, Otherwise it will be reported hibernate_sequence can not find.

* The following error can be ignored, still can achieve experimental results.

2014-10-21 11:05:31 Org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit>INFO:HCANN000001:Hibernate Commons Annotations {4.0.5. Final}2014-10-21 11:05:31org.hibernate.Version logVersionINFO:HHH000412:Hibernate Core {4.3.6. Final}2014-10-21 11:05:31 org.hibernate.cfg.Environment <clinit>INFO:HHH000206:hibernate.properties not found2014-10-21 11:05:31org.hibernate.cfg.Environment buildBytecodeProviderINFO:HHH000021:Bytecode provider Name:javassist2014-10-21 11:05:31org.hibernate.cfg.Configuration configureINFO:HHH000043:Configuring from Resource:hibernate.cfg.xml2014-10-21 11:05:31org.hibernate.cfg.Configuration getConfigurationInputStreamINFO:HHH000040:Configuration Resource: Hibernate.cfg.xml2014-10-21 11:05:31org.hibernate.cfg.Configuration addResourceINFO:HHH000221:Reading mappings from resource:com/sinosoft/config/Person.hbm.xml2014-10-21 11:05:31org.hibernate.cfg.Configuration doConfigureINFO:HHH000041:Configured sessionfactory:NULL2014-10-21 11:05:31Org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configurewarn:hhh000402: Using Hibernate built-in Connection Pool (not forProduction use!)2014-10-21 11:05:31Org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl Buildcreatorinfo: Hhh000401:using driver [Oracle.jdbc.driver.OracleDriver] at URL [jdbc:oracle:thin:@127.0.0.1:1521: ORCL]2014-10-21 11:05:31Org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl Buildcreatorinfo: Hhh000046:connection properties: {User=HJS, password=****}2014-10-21 11:05:31Org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl Buildcreatorinfo: Hhh000006:autocommit mode:false2014-10-21 11:05:31Org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configureinfo:hhh000115: Hibernate Connection Pool Size:(Min=1)2014-10-21 11:05:31 Org.hibernate.dialect.Dialect <init>INFO:HHH000400:Using Dialect:org.hibernate.dialect.OracleDialect2014-10-21 11:05:32 Org.hibernate.dialect.Oracle9Dialect <init>WARN:HHH000063:The Oracle9dialect dialect have been deprecated; use either Oracle9idialect or Oracle10gdialect Instea D2014-10-21 11:05:32 Org.hibernate.dialect.OracleDialect <init>WARN:HHH000064:The Oracledialect dialect have been deprecated; use oracle8idialect instead2014-10-21 11:05:32Org.hibernate.engine.jdbc.internal.LobCreatorBuilder useContextualLobCreationINFO:HHH000424:Disabling Contextual LOB creation as Createclob () method threw Error:java.lang.reflect.InvocationTargetException2014-10-21 11:05:32Org.hibernate.engine.transaction.internal.TransactionFactoryInitiator initiateServiceINFO:HHH000399:Using defaultTransaction strategy (direct JDBC transactions)2014-10-21 11:05:32 org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory <init>

* In the main method of the test class above

Transaction tx=session.begintransaction (); This means that if a transaction is opened, a tx.begin () is added, and the statement will give an error.
Hope you can debug success.

Web Engineering uses hibernate alone (for testing and getting started with hibernate)

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.