Finally, the hibernate test is successful! Not easy! Haha!

Source: Internet
Author: User

1. the following files are used:

① Test. Java, userinfo. Java, hibernate. cfg. XML, userinfo. HBM. xml

② The above files must be put in the src directory. Of course, it must be put in this directory. I am not sure yet.

③ I put the JDBC package and hibernate package both under tomcat/common/lib, also put in the project/WEB-INF/classes/

Next, the online documents should be placed under the classes. Otherwise, some other problems may occur. I have not tested the details, but I want

It should be placed under the classes; otherwise, what should I do when I upload the package to the server? But the question is, how can I use JDOM? This

Is not clear yet.

2. The following are the errors from start to end and solutions:

① Org. hibernate. hibernateexception: dialect class not found: net. SF. hibernate. dialect. sqlserverdialect

This is because my assertions are net. SF. hibernate. dialect. sqlserverdialect, and my hibernate version is 3rd, so I want

Change to org. hibernate. dialect. sqlserverdialect.

② New configuration (). Configure (). buildsessionfactory () = method threw 'java. Lang. noclassdeffounderror'

Exception. For better troubleshooting, I split this statement:

Configuration CFG = new configuration (). Configure ("/hibernate. cfg. xml ");
Sessionfactory Sf = cfg. buildsessionfactory ();

The following error is reported: cfg. buildsessionfactory () = method threw 'java. Lang. noclassdeffounderror 'exception

This problem occurs because the JTA. jar package is not put in. It is said that it is a tomcat version problem and does not exist in tomcat5.0.

③ E: org. hibernate. hibernateexception =

{Org. hibernate. propertynotfoundexception @ 3238} "org. hibernate. propertynotfou

Ndexception: cocould not find a getter for ID in class userinfo"

E: org. hibernate. hibernateexception =

{Org. hibernate. propertynotfoundexception @ 3307} "org. hibernate. propertynotfou

Ndexception: cocould not find a getter for username in class userinfo"

This is because the format of the get and set methods in userinfo. Java is incorrect, so you have to figure out how to automatically generate these methods.

④ A. E: org. hibernate. hibernateexception =

{Org. hibernate. Exception. jdbcconnectionexception @ 3557} "org. hibernate. doesn t

Ion. jdbcconnectionexception: cannot open connection"

B. sqle: Java. SQL. sqlexception =

{Java. SQL. sqlexception @ 3559} "Java. SQL. sqlexception: no suitable driver"

C. Session. begintransaction () = method threw

'Org. hibernate. Exception. jdbcconnectionexception' exception.

D. E: org. hibernate. hibernateexception =

{Org. hibernate. mappingexception @ 2911} "org. hibernate. mappingexception:

Invalid configuration"

E. Cause: Java. Lang. throwable =

{Org. xml. Sax. saxparseexception @ 2916} "org. xml. Sax. saxparseexception:

Content of element type/"hibernate-configuration/" must match/"(Session-factory, security ?) /"."

F. session. begintransaction () = method threw org. hibernate. Exception. jdbcconnectionexception 'exception.

G. E: org. hibernate. hibernateexception =

{Org. hibernate. Exception. jdbcconnectionexception @ 3567} "org. hibernate. doesn t

Ion. jdbcconnectionexception: cannot open connection"

H. sqle: Java. SQL. sqlexception =

{Java. SQL. sqlexception @ 3569} "Java. SQL. sqlexception: [Microsoft] [sqlserver

2000 driver for JDBC] Error establishing socket ."

These problems are caused by configuration errors in hibernate. cfg. xml. The most important problems are the following two:

<Property name = "connection. driver_class"> com. Microsoft. JDBC. sqlserver. sqlserverdriver </property>

<Property

Name = "connection. url"> JDBC: Microsoft: sqlserver: // localhost: 1433; databasename = testhibernate; selectmethod = cursor

</Property>

⑤ Tx. Commit () = method threw 'org. hibernate. Exception. constraintviolationexception' exception.

When identity_insert is set to off, explicit values cannot be inserted into the 'userinfo' column.

I can solve the problem by changing increment to native, but the specific generator has to go to the materials for research.

3. Other considerations

① <Mapping Resource = "userinfo/user. HBM. xml"/> the directory specified by this resource is relative to the classes

② Another problem was encountered at the end, but the result was not affected.

Javax. Naming. namingexception: context is read only

The reason why Tomcat does not support dynamic binding to JNDI is unclear.

Refer to this page (http://topic.csdn.net/t/20050222/09/3796914.html)

4. There are still a lot of problems in the back, there are no books to read, there is no money to buy, ah, how can I live ........

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.