Notes by Dr. Xi
Displaying notes 31 - 40
Created by Dr. Xi on March 22, 2010 01:50:49
The class org.apache.xerces.jaxp.SAXParserFactoryImpl extends javax.xml.parsers.SAXParserFactory , so casting the former to the latter should not be a problem. This error occurs when there are two copies of javax.xml.parsers.SAXParserFactory loaded by two different class loaders, and you are trying to cast one to the other. Normally, you'll be able to find xml-apis.jar under WEB-INF/lib of the WAR file. Deleting the jar will resolve the problem. java.lang.ClassCastException: org.apache.xerces.jaxp.SAXParserFactoryImpl cannot be cast to javax.xml.parsers.SAXParserFactory at javax.xml.parsers.SAXParserFactory.newInstance(Unknown Source) at org.apache.commons.digester.Digester.getFactory(Digester.java:478) at org.apache.commons.digester.Digester.getParser(Digester.java:683) at org.apache.commons.digester.Digester.getXMLReader(Digester.java:891) at org.apache.commons.digester.Digester.parse(Digester.java:1591) at org.apache.struts.action.ActionServlet.initServlet(ActionServlet.java:1144) at org.apache.struts.action.ActionServlet.init(ActionServlet.java:328) at javax.servlet.GenericServlet.init(GenericServlet.java:242)
Created by Dr. Xi on March 18, 2010 21:37:41
You run an update and it hangs. Use this query to find out who's locking the table. select o.object_type, o.object_name, DECODE(v.locked_mode, 1, 'no lock', 2, 'row share (SS)', 3, 'row exclusive (SX)', 4, 'shared table (S)', 5, 'shared row exclusive (SSX)', 6, 'exclusive (X)') lock_mode, v.oracle_username, v.os_user_name, v.session_id from all_objects o, v$locked_object v where o.object_id = v.object_id;
Created by Dr. Xi on March 02, 2010 00:07:48
OC4J didn't offer much help in the console. This is all it displayed: 2010-03-01 15:48:21.372 ERROR J2EE EJB-03027 [FabulousApp] An error occured deploying EJB module: com.evermind.server.ejb.exception.DeploymentException: [FabulousApp:TheEJBModule] - Exception creating EntityManagerFactory using PersistenceProvider class org.hibernate.ejb.HibernatePersistence for persistence unit DefaultPU. 10/03/01 15:48:21 WARNING: Application.setConfig Application: FabulousApp is in failed state as initialization failed. java.lang.InstantiationException: Error initializing ejb-modules: [FabulousApp:TheEJBModule] - Exception creating EntityManagerFactory using PersistenceProvider class org.hibernate.ejb.HibernatePersistence for persistence unit DefaultPU. 2010-03-01 15:48:21.403 WARNING J2EE OJR-00013 Exception initializing deployed application: FabulousApp. Application: FabulousApp is in failed state as initialization failed However, in the em console, Logs -> Diagnostic Logs gives more details: Message Text [FabulousApp] An error occured deploying EJB module: com.evermind.server.ejb.exception.DeploymentException: [FabulousApp:TheEJBModule] - Exception creating EntityManagerFactory using PersistenceProvider class org.hibernate.ejb.HibernatePersistence for persistence unit DefaultPU. Supplemental Text ...
Created by Dr. Xi on February 24, 2010 21:13:05
Last update: February 24, 2010 21:19:54
This program demonstrates the use of the java.nio package to implement a single thread echo server. import java.io.IOException; import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.Socket; import java.net.SocketAddress; import java.nio.ByteBuffer; import java.nio.channels.SelectionKey; import java.nio.channels.Selector; import java.nio.channels.ServerSocketChannel; import java.nio.channels.SocketChannel; import java.util.*; public class EchoServer { private InetAddress addr; private int port; private Selector selector; private Map<SocketChannel,List<byte[]>> dataMap; public EchoServer(InetAddress addr, int port) throws IOException { this.addr = addr; this.port = port; dataMap = new HashMap<SocketChannel,List<byte[]>>(); startServer(); } private void startServer() throws IOException { // create selector and channel this.selector = Selector.open(); ServerSocketChannel serverChannel = ServerSocketChannel.open(); serverChannel.configureBlocking(false); // bind to port InetSocketAddress listenAddr = new InetSocketAddress(this.addr, this.port); serverChannel.socket().bind(listenAddr); serverChannel.register(this.selector, SelectionKey.OP_ACCEPT); log("Echo server ready. Ctrl-C to stop."); // processing while (true) { // wait for events this.selector.select(); // wakeup to ...
Created by Dr. Xi on February 18, 2010 21:17:34
-- add a foreign key to abother table alter table BOOKS add constraint BK_ATHR_FK foreign key (AUTHOR_ID) references AUTHORS (AUTHOR_ID); -- add a foreign key to same table -- PARENT_MENU_ID is a foreign key to primary key MENU_ID alter table MENUS add constraint MENU_MENU_FK foreign key (PARENT_MENU_ID) references MENUS (MENU_ID);
Created by Dr. Xi on February 18, 2010 21:04:13
-- disable foreign key alter table my_table disable constraint mytbl_col_othr_tbl_col_fk; -- enable foreign key alter table my_table enable constraint mytbl_col_othr_tbl_col_fk;
Created by Dr. Xi on February 18, 2010 20:39:59
Last update: February 18, 2010 20:41:17
Oracle provides two functions for string replacement: REPLACE and TRANSLATE . REPLACE replaces one substring with another: -- Replace John with Bob select REPLACE('Hello John', 'John', 'Bob') from dual; -- Match is case sensitive, lower case john won't match select REPLACE('Hello John', 'john', 'Bob') from dual; TRANSLATE replaces one character by another, position for position: -- rot13 in Oracle SQL select TRANSLATE('Hello John', 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz', 'NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm') from dual; -- Remove all question marks select TRANSLATE('How? are? you?', '.?', '.') from dual; -- This does not work! select TRANSLATE('How? are? you?', '?', '') from dual;
Created by Dr. Xi on February 15, 2010 06:09:56
Last update: February 16, 2010 03:08:34
The context root of a web application determines the root path of URLs that will be handled by that application. For example, if the context root is example , then URLs starting with /example (i.e., /example/* ) will be handled by that application. By default, Tomcat uses the WAR file name (without the .war extension) or, if deployed in exploded directory form, the name of the top level directory as the context root . For example, the pre-installed examples application is deployed under the examples directory under webapps , and its context root is examples . You may want to use a different context root than Tomcat's default. For example, if you build your application with Maven, the resulting WAR file might be named my-fabulous-app-1.0-SNAPSHOT.war ...
Created by Dr. Xi on February 14, 2010 23:00:53
Last update: February 16, 2010 03:20:24
Tomcat auto-deploys WAR files or exploded web applications copied to the appBase directory by default. The default Host configuration in server.xml looks like this: <!-- Define the default virtual host Note: XML Schema validation will not work with Xerces 2.2. --> <Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false"> So the appBase directory is named webapps by default, which is where the manager and examples applications are. You can deploy a new application by dropping your WAR file, or copying your application in exploded WAR structure to the same directory. Your application is automatically re-deployed when a new WAR file is copied to webapps , or, in exploded structure, WEB-INF/web.xml is updated. The reason that Tomcat knows to reload a web application when web.xml is updated ...
Created by Dr. Xi on February 13, 2010 22:52:18
This runtime error happens when the Sun EL implementation is not available. Look for the class com.sun.el.ExpressionFactoryImpl in your deployment package, you probably won't find it, or you'll find a version that can't be loaded in your deployment environment. If you are using Maven to build, you can add the following repository and dependency in pom.xml : <!-- Project dependencies --> <dependencies> <dependency> <groupId>com.sun.el</groupId> <artifactId>el-ri</artifactId> <version>1.0</version> <scope>runtime</scope> </dependency> </dependencies> <repositories> <!-- Repository for EL --> <repository> <id>maven2-repository.dev.java.net</id> <name>Java.net Repository for Maven</name> <url>http://download.java.net/maven/2/</url> <layout>default</layout> </repository> </repositories>