Initial configuration issues such as mapping, entities, data tables, etc. using hibernate

Source: Internet
Author: User
Tags log4j

Problem Description: The error, probably is to explain the mapping mapping, can not find. hbm.xml file (Resource) a large push configuration file, debug half a day of the whole blindfolded

Finally all deleted, the whole world is quiet haha. ----------------------------then re-use the MyEclipse feature to create the automatic configuration:


New Web project, project Lib copy a database connection driver Mysql-connector-java-5.1.18-bin

Right-click on the project name to select Configure Facets Manager



will automatically generate Hibernate.cfg.xml, hibernatesessionfactory files, of course, a new package to put factory files.


The next step is to automatically generate. hbm.xml files and Entity entities classes

White space Right-click New database Connection Driver



After establishing the connection, start the connection, reverse engineer the entity class and mapping file, as shown below


The configuration file is now complete.


In addition: Useunicode=true&characterencoding=utf-8 This sentence can be added to the URL of the connection database. + This statement, solve the Chinese garbled problem.


Yes, the test class is Session.save () to insert data into the database when the error, Org.hibernate.MappingException:Unknown entity:java.lang.String

How the Entity class type is string. Look at the source, I wipe, session.save ("user"), and then decisively "" Remove, haha, everything is over.


Oh, and think of one more ... Report warning, log4j something is wrong, that is, log, and then add a log4j.properties

# Configure logging for testing:optionally with log file
Log4j.rootlogger=warn, stdout
# Log4j.rootlogger=warn, stdout, logfile
Log4j.appender.stdout=org.apache.log4j.consoleappender
Log4j.appender.stdout.layout=org.apache.log4j.patternlayout
log4j.appender.stdout.layout.conversionpattern=%d%p [%c]-%m%n
Log4j.appender.logfile=org.apache.log4j.fileappender
Log4j.appender.logfile.file=target/spring.log
Log4j.appender.logfile.layout=org.apache.log4j.patternlayout
log4j.appender.logfile.layout.conversionpattern=%d%p [%c]-%m%n

It's ready to run.

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.