Java. lang. ClassCastException Solution

Source: Internet
Author: User

DB4O has been used in recent JAVA projects. It is indeed a good database. For the first time, the database used to store objects is quite fresh. It is necessary to perform basic operations on an ObjectContainer, it is more intuitive to understand than relational databases. However, using such a database can easily produce data redundancy. Otherwise, it may be difficult to query data. In addition, you must be very careful about data updates. It is easy to write data into the database due to negligence.

In the process of using it for WEB development, we encountered a very strange problem: execute the following statement

ObjectSet <Ids> allIds = db. queryByExample (Ids. class );

This statement queries All Ids class objects in the database, but it is strange that the returned result is com. db4o. reflect. generic. GenericObject, which directly causes problems in subsequent values. Why is this problem? After studying for a long time, I finally found a problem after trying constantly, the problem is that the JAR package of the db4o-7.12.145.14409-all-java5 exists under % JAVA_HOME %/jre/lib/ext and under the WEB-INF \ lib directory of the WEB project, resulting in the generation of conflicts, deleting any one of them will solve the problem. This may not be a special case. In other cases, I don't know if such an error will occur.

However, from the perspective of web engineering, it is best to put the jar file in the corresponding project's WEB-INF \ lib directory, to facilitate the transfer of web engineering, it also makes the dependency structure of the project clear, reducing unnecessary troubles. Of course, if the servlet required by the web project needs to be directly generated under the project, then you need to place the required external JAR under the jre/lib/ext directory so that the compilation will pass.

We recommend that you use ECLIPSE and other tools to directly run and test on the server. If there is no problem, copy the content under WebContent to the server directory for troubleshooting and reduce errors similar to the above.

Remind yourself, and hope to help other friends 650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/15331R292-0.gif "type =" face "alt =" java. lang. classCastException solution "title =" java. lang. classCastException solution "/>


This article from the "precipitation" blog, please be sure to keep this source http://jupiterbee.blog.51cto.com/3364619/1289638

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.