Weblog

Hibernate Criteria API

Sometimes sql (like) queries aren’t the optimal way to express what data you want to retrieve from a database. In some cases using Hibernate’s criteria API or Toplink’s Query Expressions will be more powerfull and easier to write. Especially if you can reuse query expressions. DevX has just published an article describing Hibernate’s criteria API: Hibernate Criteria API: Multi-Criteria Search Made Easy

Technorati Tags: ,

ADF BC’s readXml doesn’t work with one-to-one links

I’m currently having some problems with 1-to-1 links in bc4j. Using readXml to read data into view linked with a 1-to-1 view link doesn’t seem to work. It could be related to a problem Steve muench wrote about some time ago: ClassCastException Accessing One-To-Many Entity View Link Accessor (Bug 4113607).

I’ve created two views, Tab1View and Tab2View, and they’re linked using a 1-to-1 view link. Now i want to read the following xml document into these views:

<tab1view>
  <tab1viewrow>
    <name>some name</name>
    <tab2view>
      <tab2viewrow>
        <name>another name</name>
      </tab2viewrow>
    </tab2view>
  </tab1viewrow>
</tab1view>

Using the following code:

ViewObject tab1View = service.findViewObject("Tab1View");
DOMParser xmlParser = new DOMParser(); // Create a new XML Parser
xmlParser.parse(this.getClass().getClassLoader()
   .getResourceAsStream("bc4jtest/Data.xml"));
Element element = xmlParser.getDocument().getDocumentElement();
tab1View.readXML(element, -1);

If i run this code the following error message is displayed:

oracle.jbo.ReadXMLException: JBO-25025: RowSet with XML tag:Tab1View failed.
	at oracle.jbo.server.ViewObjectImpl.updateRowSetFromXML(ViewObjectImpl.java:10243)
...
## Detail 0 ##
java.lang.NullPointerException
	at oracle.jbo.server.ViewRowImpl.readAttrsFromXML(ViewRowImpl.java:2929)
...

The easiest way to avoid this problem is to change the association and view link to a 1-to-many relation. This is the work around i’m using. Another option would be to change the view objects, by including all the attributes of Tab2View into Tab1View. Apart from this problem, bc4j’s readXml is pretty usefull.

Bruce Tate on Persistence frameworks

JavaBoutique has published an interesting interview with Bruce Tate: Interview: Bruce Tate on the “Politics of Persistence”. (I’m not sure if this is a new article, I can’t find the publish date anywhere. This is actually number 3 in Jakob Nielsen’s Top Ten Web Design Mistakes of 2003: Undated Content.)

Bruce has some good advice on which frameworks to use for ORM:

I typically tell a customer to start with the simplest possible solution. The simplest is JDBC…The most important of the JDBC-wrapping frameworks called iBATIS… The iBATIS framework differs from the typical object relational mapping framework in that you’re mapping to the results of an SQL query instead of a relational schema… If iBATIS isn’t enough, I try Hibernate… If Hibernate isn’t enough, I move to something like JDO… Now there’s also the emerging EJB3 standard… is a merger of EJB and JDO into a combined persistence specification.

But ORM frameworks don’t mean you don’t have to know anything about databases:

Making the conscious decision to isolate yourself from the work of writing code is different from isolating yourself from understanding the details of the relational database… You can use Hibernate effectively because you understand what’s going on under the covers.

He also gives his opinion about Toplink and the future of persistence frameworks. Worth a read.

JDBC 4.0 enhancements

JDJ has a usefull article on some of the changes planned for JDBC 4.0: JDBC 4.0: A Significant Advance on the Standard and Features Worth the Wait. The main improvements listed:

  • Support for XML datatypes in the database
  • Improved connection and statement pooling
  • More refined SQLExceptions
  • These are all usefull features, but it will be a while before we can use them. JDBC 4.0 is part of J2SE version 6.0, which is scheduled for release sometime next year. And it will be at least another year before we’ll start to see application servers supporting J2SE 6.0.

    JSF + AJAX = ADF.Faces.NEXT

    Some Oracle bloggers have been writing and hinting about what oracle is doing with AJAX and JSF. Especially Jonas Jacobi has provided some interesting information about current developments at Oracle.

    Oracle’s JSF implementation is called ADF Faces. Introduction to JSF components and the ADF Faces Components is a small introduction to Oracle ADF Faces:

    …Oracle ADF includes well over 100 JSF components (ADF Faces) that provide end users with a very rich and powerful experience. There are components like color pickers, list of values and calendars…

    All these components currently use HTML and WML as the markup languages…

    Oracle is in the midst of revamping the renderers of these components by adding a combination of DHTML and JavaScript support, which will provide an even richer user experience, including partial page rendering. This new render kit, called the rich client, is so powerful that it almost deprecates the use of Swing.

    This last statement comes with a screenshot showing a rich user interface in a webbrowser, titled: ADF.Faces.NEXT.

    DHTML, Javascript, partial page rendering, this all sound a lot like what most people today call AJAX. A big post about the basics of AJAX can be found on Tug’s blog: Web UI: What’s behind AJAX? Simple use cases using XMLHttpRequest

    Jonas Jacobi writes why JSF would be the right technology to support AJAX in his post: Quote – “JSF is not a rich client technology”:

    One of the key differentiators of JavaServer Faces (JSF) is its ability to be markup agnostic, allowing you to attach any available presentation technology (HTML, DHTML, Telnet/Character mode and eventually SVG, Flash, XUL, etc.) to a set of reusable components.

    And this is what Oracle has been doing as can be read in his post Wireless development with JSF

    ADF Faces EA16 supports XHTML … We are working on an additional richer render kit support what has lately been known as Ajax (XHTML, XmlHttpRequest, JavaScript, and DOM.

    And it looks like some screenshots have been posted recently which display these AJAX components in action. Justin Kestelyn posted some impressive looking Oracle BAM screenshots: New Oracle BAM Screenshots. His post doesn’t mention the technology used in these screenshots, but you can see the application is running in internet explorer. However, it could technically still be webforms or something similar. But we see a lot of graphs, which could be the BI components Jonas Jacobi is writing about in Wireless development with JSF:

    leveraging JSF as the base … our Business Intelligence team is working on a set of ADF Faces BI components

    Grant Ronald is also blogging about web applications with a rich gui: So can you have a productive end user with a pure web application? Included are some interesting screenshots: 1 (no longer available), 2, 3, 4 & 5 . Grant doesn’t tell us if this application is built using JSF, but if you hover over the pictures you see a hint with the following text: “Faces UI”.

    So it looks like we’ll soon see JSF components with support for AJAX technology. When can we expect this? Again, Jonas Jacobi gives us a hint in JSF renderers for mobile devices, xhtml:

    When we go production with JDeveloper 10.1.3 we will have Telnet, PDA’s, and ASK (IM, SMS, MMS, SMTP, Paging, etc..,) support, and also integration with peripheral devices such as scanners, portal printers

    And in Quote – “JSF is not a rich client technology” he writes about ADF.Faces.NEXT:

    We are still not there to be able to provide you with an early access release of these components until earliest August 2005. Work that is currently on going is to get the underlying framework together so that the components can support e.g. drag and drop

    I guess it’s save to say that JDeveloper 10.1.3 will include ADF Faces, but no support for AJAX. But as the screenshots show, AJAX support is progressing quite nicely.

    I think Oracle is building a real alternative for Oracle Forms, a technology which will allow you to build rich gui data entry applications (and ofcourse a lot of other types of applications as well), but this time it’s build on open standards. And you’ll also be able to use your applications on pda’s (or smart phones)and through telnet.

    Technorati Tags: , , ,

    Jdeveloper jgoodies forms support

    Support for JGoodies Forms is coming to JDeveloper, which is great news. On my current project we’re using JGoodies looks, to make our Swing application look more windows like (and, btw, none of our end users has ever complained about the fact that the swing application doesn’t look like a native windows application), but we’ve mostly been using GridBagLayout to implement forms. I actually like the GridBagLayout, once you know how to use it, it’s really flexible, and the forms look good enough. It also helps that JDeveloper visual swing editor is pretty good. I only wish JDeveloper would allow you to set the GridBagLayout constraints for more than one cell at a time.

    Oracle changes policy on multicore… a little

    Just found the following article on eweek: Oracle Caves on Multicore licensing.

    A core is only 0.75 times a cpu:

    Licensing terms for the Oracle Store Web site now state that, for the purposes of counting how many processors need to be licensed, a multicore chip with “n” cores will be multiplied by 0.75. Oracle will then round up fractions to the next whole number.

    Java jar dependency management using Ivy

    Along with our source code, we’ve also been putting all required jars into cvs, basically for two reasons:

    • The build process controlled by cruisecontrol needs the jars, but cruisecontrol runs on a server where we don’t want to install an IDE (jdeveloper). We’ve put all adf, bc4j and other required jars into cvs, and when the build process compiles the application, it first gets all the required source code and the required jars, so no need for jdeveloper.
    • We want version control on dependencies. If you check out the code for release 1, you need the jars that release 1 depends on. If you check out release 2, you will need different jars.

    So just relying on the project dependencies in jdeveloper is not an option.

    The downside to this approach however, is that we get a lot of jars in cvs, and many projects use the same jar files, so it’s bit of a waste. For some time, i thought the solution would be to move from using ant to using maven for building the code. However, some weeks ago, i discovered ivy. Ivy is a java dependency manager, which you can easily use in existing projects using ant.

    I’ve just added ivy to our first project. Below i’ll describe the steps to implement dependency management using ivy.

    I’ve added the following target to all our ant build files. It gets all the required jar files and stores them in a lib directory in your project. You need to put this before the target which compiles your code.

      <target name="resolve.dependencies">
        <taskdef name="ivy-retrieve"
                         classname="fr.jayasoft.ivy.ant.IvyRetrieve">
          <classpath refid="classpath"/>
        </taskdef>
        <ivy-retrieve pattern="${ivy.lib.dir}/[artifact].[ext]"/>
      </target>
    

    Next step: I’ve added a new workspace and project in jdeveloper which acts as a jar repository for all for all projects. On the cruisecontrol server, this workspace is also checked out of cvs, and the ivy target described above, copies the jar files from this jar repository. The file structure of this workspace is as follows:

    ./oracle
    ./oracle/bc4j
    ./oracle/bc4j/10.1.2
    ./oracle/bc4j/10.1.2/bc4jct.jar
    ./oracle/bc4j/10.1.2/bc4jhtml.jar
    ./oracle/bc4j/10.1.2/bc4jmt.jar
    ./oracle/bc4j/10.1.2/ivy.xml
    ./oracle/adf
    ./oracle/adf/10.1.2
    ./oracle/adf/10.1.2/adf-controller.jar
    ./oracle/adf/10.1.2/adfm.jar
    ./oracle/adf/10.1.2/ivy.xml
    ...
    

    As you can see, it contains all the jar files used by other projects. Every directory also contains an ivy.xml file which describe the dependencies of the jars in that directory.

    For example, the ivy.xml file in the adf directory looks like this:

    <ivy-module version="1.1">
      <info organisation="oracle" module="adf" revision="10.1.2" status="release"/>
      <publications>
        <artifact name="adfm" type="jar"/>
        <artifact name="adftags" type="jar"/>
        <artifact name="adf-controller" type="jar"/>
      </publications>
      <dependencies>
        <dependency org="apache" name="commons-el" rev="1.0">
          <artifact name="jsp-el-api" type="jar"/>
          <artifact name="commons-el" type="jar"/>
        </dependency>
        <dependency org="sun" name="servlet" rev="2.3"/>
        <dependency org="oracle" name="jsp-el" rev="1.0">
          <artifact name="oracle-el" type="jar"/>
        </dependency>
        <dependency org="oracle" name="bc4j" rev="10.1.2">
          <artifact name="bc4jmt" type="jar"/>
          <artifact name="bc4jct" type="jar"/>
          <artifact name="bc4jhtml" type="jar"/>
          <artifact name="bc4jdomorcl" type="jar"/>
        </dependency>
        <dependency org="apache" name="struts" rev="1.1"/>
        <dependency org="apache" name="commons-beanutils" rev="1.6.1"/>
        <dependency org="sun" name="collections" rev="1.0"/>
        <dependency org="oracle" name="jdev" rev="10.1.2">
          <artifact name="jdev-rt" type="jar"/>
        </dependency>
        <dependency org="sax" name="sax" rev="2.0.1"/>
      </dependencies>
    </ivy-module>
    

    So it specifies that the adf libraries depend on sax.jar, jdev-rt.jar, and some other libraries. In your application project you only have to specify that your application depends on adf, and ivy will automatically download the adf jars and any jars required by adf.

    Next, i had to specify the dependencies of my application. The following ivy.xml file describes the dependencies of a view controller project build using adf, bc4j, jsp’s and struts:

    <ivy-module version="1.0">
      <info organisation="nl.iteye" module="ViewController"/>
      <dependencies>
        <dependency org="hunsicker" name="jalopy-ant" rev="0.6.1"/>
        <dependency org="apache" name="struts" rev="1.1"/>
        <dependency org="sun" name="servlet" rev="2.3"/>
        <dependency org="oracle" name="jdev" rev="10.1.2">
          <artifact name="ojmisc" type="jar"/>
          <artifact name="jdev-rt" type="jar"/>
          <artifact name="jdev-cm" type="jar"/>
        </dependency>
        <dependency org="oracle" name="bc4j" rev="10.1.2">
          <artifact name="bc4jhtml" type="jar"/>
        </dependency>
        <dependency org="apache" name="struts" rev="1.1"/>
        <dependency org="oracle" name="adf" rev="10.1.2">
          <artifact name="adf-controller" type="jar"/>
          <artifact name="adftags" type="jar"/>
        </dependency>
      </dependencies>
    </ivy-module>
    

    That’s about it. Creating the repository containing the jar files, and the ivy.xml files describing their dependencies takes some time. A great help here is the jarjar tool.

    Technorati Tags: , , ,

    First BPEL Patch Arrived

    On July 12th, Oracle released patch-01 for the BPEL Process Manager. This patch adressess mostly some finetuning in the use of XPATH, conformation to WS-I and instance recovery. I’m happy to see that Oracle goes ahead full steam on BPEL.

    The patch is a GENERIC patch and can be used across Windows/Linux/Solaris installations. More details can be found on Metalink (patch number 4406640) or here.

    Easy publishing of a Struts application as a Portlet in Oracle Portal

    To publish an Apache Struts web application as a portlet in Oracle portal, you have to make sure that every page forward/redirect stays in the Portal context. This is quite easily to do.

    Assuming you are developing in Jdeveloper, you have to install the Portlet Development Kit-plugin for JDeveloper. This installs the portlet tag library that includes all the tags to make your struts page portlet enabled. You now have to include the portlet-tag-library with your struts-project.

    To make sure that every page forward/redirect stays in the portal context, you have to change the form, href, img tags in your jsp pages to the portlet specific pages. Here’s an example:

    <pdk-struts-html:form action="/editStep.do" method="post">
            <jsp :include page="include/edit.jsp"/>
    </pdk-struts-html:form>
    

    In the above example you can see that the special

    <pdk-struts-html:form></pdk-struts-html:form>

    is used.

    Of cource, you don’t want to write seperate views for both the stand-alone version and the portlet-enabled version of your struts webapplication. To integrate both views in one, you have to detect in a page from where the request is coming and decide which tag to use. To realize this, you have to write your own custom ActionServlet that overwrites the default ActionServlet and stores the request-source in a session variable. The code-sample below implements this custom ActionServlet.

    public class CustomActionServlet extends ActionServlet {
      public CustomActionServlet() {
      }
    
      protected void process(
        HttpServletRequest request
      , HttpServletResponse response
      ) throws IOException, ServletException {
    
        PortletRenderRequest pReq    = (PortletRenderRequest)
          request.getAttribute(HttpCommonConstants.PORTLET_RENDER_REQUEST);
        boolean isPortal = false;
        if(pReq == null) {
          isPortal = false;
        }
        else
          isPortal = true;
    
        request.setAttribute("portal_request_detected"
          ,new Boolean(isPortal));
        super.process(request, response);
      }
    

    Now the code in the page becomes:

    <c:if test="${!requestScope.portal_request_detected}">
        <html:form method="post" action="/editStep.do">
            <jsp :include page="include/edit_uitvoering_inc.jsp"/>
        </html:form>
    </c:if>
    <c:if test="${requestScope.portal_request_detected}">
       <pdk-struts-html:form action="/editStep.do" method="post">
            <jsp :include page="include/edit_uitvoering_inc.jsp"/>
        </pdk-struts-html:form>
    </c:if>
    

    Now your page can either be viewed in Portal as a portlet or stand-alone in a webbrowser.

    Technology
    Ben jij slim genoeg voor IT-eye