tag:blogger.com,1999:blog-35168303792300856292024-02-20T09:56:34.876+01:00Java NotepadPuchehttp://www.blogger.com/profile/14406061190185738856noreply@blogger.comBlogger9125tag:blogger.com,1999:blog-3516830379230085629.post-75742334714377405432012-02-03T13:55:00.008+01:002012-02-03T20:18:31.393+01:00Tricky Java exceptions quizIf you think you know everything about throwing and handling exceptions in Java, try to find the right answer for this couple of questions I have come across. You can find the right answers at the end of this post, or by testing it on your own computer.Question 1. What exception will be thrown from the following block of code?try { throw new TryException();}catch { throw new CatchException();}Unknownnoreply@blogger.comtag:blogger.com,1999:blog-3516830379230085629.post-20247876741146530832007-10-29T23:09:00.000+01:002007-10-30T09:05:58.527+01:00My problems putting RichFaces to workThere are many open source JSF component libraries in the market. So I had to choose one among them for my JSF projects. After some exhaustive exploration, I chose Ajax4jsf and RichFaces (now both projects are merged) as my component library because of the ajax-enabled components and also because I think it has enough JSF components to work with.I read the RichFaces Developer Guide, and followed Puchehttp://www.blogger.com/profile/14406061190185738856noreply@blogger.comtag:blogger.com,1999:blog-3516830379230085629.post-39645387300319633882007-09-30T21:37:00.000+02:002007-10-01T08:58:33.009+02:00instanceof doesn't work with Generics!The information of generic types are not accessible at runtime. Contrary to what happens in other languages such us C++, this can be seen as a limitation that we, Java programmers, must bear with.Simple scenarioAs a sample scenario to show up the problem, we´ll write a simple generic Pair class containing a pair of objects of the same given parameter type T.If you try to write a code such as thisPuchehttp://www.blogger.com/profile/14406061190185738856noreply@blogger.comtag:blogger.com,1999:blog-3516830379230085629.post-25229400390620405012007-08-02T14:47:00.000+02:002007-11-05T13:15:33.819+01:00Managing JPA EntityManager lifecycleManaging EntityManager lifecycle when using JPA in a non enterprise environment (e.g. Tomcat) is a custom task you must take care of by yourself for you don't have the IoC (Dependence Injection) of a Java EE 5 to manage the EntityManager lifecycle. It happened the same when we discussed the EntityManagerFactory lifecycle in a previous post. Therefore, in this situation, you should consider the Puchehttp://www.blogger.com/profile/14406061190185738856noreply@blogger.comtag:blogger.com,1999:blog-3516830379230085629.post-74503448813371744462007-07-26T22:04:00.000+02:002007-07-26T23:31:05.747+02:00Working with a non JTA DataSource in Toplink EssentialsAs it is commonly known, Toplink Essentials, as a JPA engine, can be used both inside a Java EE 5 application server and outside an EJB container in a Java Standard Edition (Java SE) 5 application.However, if you are working with JPA outside an EJB container, you would have known that by default you can't define a data source to work with in your persistence.xml archive. You just need to define Puchehttp://www.blogger.com/profile/14406061190185738856noreply@blogger.comtag:blogger.com,1999:blog-3516830379230085629.post-47754102303452796122007-06-28T22:32:00.000+02:002007-06-29T12:54:11.079+02:00How to close a JPA EntityManger in web applicationsWhen working with resources it's always important to ensure they are closed when not longer needed. Working with JPA there are two kind of resources we can take care of: EntityManager and transactions.Context As of Java EE, you can use IoC to inject an EntityManager so the Container is the one who manage the whole life cycle of EntityManagers. The context we are referring here is when no such a Puchehttp://www.blogger.com/profile/14406061190185738856noreply@blogger.comtag:blogger.com,1999:blog-3516830379230085629.post-66639217800487839242007-05-21T08:49:00.000+02:002007-06-29T13:13:43.447+02:00Bug in Hibernate implementation of JPA: Persisting an entityI've found a bug in the Hibernate implementation of JPA when persisting an entity. I'm working with JPA using two different JPA implementations: Hibernate EM and Toplink Essential, and I've found certain interesting conditions (I'm to describe) upon which Hibernate throws an unexpected exception that I think it shouldn't. The observation The exception I obtained was this:Puchehttp://www.blogger.com/profile/14406061190185738856noreply@blogger.comtag:blogger.com,1999:blog-3516830379230085629.post-10059535852377809582007-05-04T08:47:00.000+02:002007-07-24T14:34:15.933+02:00JPA EntityManagerFactory in web applications Coding Java Persistence web applications that run outside a Java EE Server (e.g. Apache Tomcat) is slightly different from JPA applications inside an Application Server. The main difference has to do with the responsibility to manage the EntityManagerFactory lifecycle. Because there is no Dependence Injection outside the Java EE Server, this responsibility fall directly on Puchehttp://www.blogger.com/profile/14406061190185738856noreply@blogger.comtag:blogger.com,1999:blog-3516830379230085629.post-23702582949167231882007-04-13T13:23:00.000+02:002007-06-29T12:53:05.078+02:00Publishing JSF application from behind a proxy Problem Sometimes application servers are located behind a web proxy, so that the contents that they publish is available from a general URL space. For example, the web server www.acme.es acts as a proxy for the web application server srv3.acme.es, so that every web page which is published like http://srv3.acme.es/* are accessible from http://www.acme.es/srv3/*. The problem is that links Unknownnoreply@blogger.com