ManyToOne reference loading with JPA/Hibernate

In this example an InvestigationType has many SampleType’s. If I load an InvestigationType via em (entity manager) find it also loads the samples. InvestigationType inv2 = (InvestigationType) em.find( InvestigationType.class, inv.getId()); System.out.println(“Inv2 ID="+inv2.getId()); System.out.println(“Inv2 Title="+inv2.getTitle()); assertTrue(inv2.getSample().size() == 2); However, if I load a SampleType the investigation field is null, unless I refresh the object. // Get a sample SampleType s3 = (SampleType) em.find( SampleType.class, inv2.getSample().get(0).getId()); em.refresh(s3); System.out.println(convertDataToXmlString(s3)); InvestigationType inv3 = s3.getInvestigation(); assertNotNull(inv3); From my understanding I should not have to do this as the fetching should be the same in both instances, ie resolving the parent by default. Similarly, if I query for both objects the references are correctly loaded. ...

January 8, 2008 · Nigel Sim

Hibernate, spring, and different jars

The situation is this. I had a working application which used Hibernate annotated classes, and JTA for data bindings, within a spring framework. Then I moved the annotated classes into a Jar file, and the application stopped working. Hibernate knew nothing about the classes because the PersistenceAnnotationBeanPostProcessor does not traverse into the JARS on the classpath. Further neither the entity manager or HibernateJpaVendorAdapter have options to specify the explicit paths to the classes. ...

November 25, 2007 · Nigel Sim

Spring 2.0.6 and ACEGI

Because ACEGI depends on spring 1.2.6, we need to override a few dependencies if we want to use spring 2.0.6. To do this, we use the following exclusions:

October 1, 2007 · Nigel Sim

Setting up Tomcat behind Apache 2.2 in a hierarchical path

The situation I want to deal with is this: Public Web Root |-plone \-portals |-portal1 (server A) \-portal2 (server B) In apache 2.2 they (the writers of the Apache docs) seem to prefer the use of mod_proxy_ajp, which is an AJP/1.3 driver for mod_proxy. At the apache end we just install mod_proxy_ajp and add a line such as the following to the proxy_ajp.conf file: ProxyPass /portals/portal1 ajp://nigel-dev:8009/portals/portal1 Note that the paths on the proxy host and the application server are the same. This is important, as at the application end it will only know its path name from its context, and unless you want to do some url rewriting, and possible use something called ProxyHTMLURLMap. It, like most potentially useful software, isn’t available in Red Hat, so we can’t investigate this option. ...

September 28, 2007 · Nigel Sim

Maven-Ant hybrid

Some brief background. Ant is the stock standard Java build system, much as Make is for C/C++. Maven is a newer Java build system which tried to, amongst other things, solver the Jar dependency hell problem, as well as make a standard project directory layout. From the Maven guide: <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>1.2.9</version> </dependency> Now when you go to compile with maven it goes and gets all the dependencies, puts them in your local repository (~/.m2/repository) and then into your project’s build class path. This is covered in more detail at the Maven website. ...

July 20, 2007 · Nigel Sim

Four things which would make my Linux wonderful

1. Presentation controller for my bluetooth phone In fact this already exists, in many forms apparently. The trick for me was to get it working. If I was to derive it from scratch I would have made a simple, mappable Java app for the phone, and would have written a Python app for the server. In fact this already exists in Xbtrc. The trick for me however, was to get the phone to find the computer. The phone could find other phones, and using the python rfcomm examples, I found the computers could find each other. The problem, it turns out, was the computer needs to be put into discoverable mode for the phone to be able to find it. ...

January 18, 2007 · Nigel Sim

Java HTML Table parser

I put together this class for scraping HTML tables. It supports nested tables. At some stage I’ll put this up in SVN along with it’s test cases. import java.io.IOException; import java.io.Reader; import java.util.ArrayList; import java.util.Stack; import javax.swing.text.MutableAttributeSet; import javax.swing.text.html.HTML; import javax.swing.text.html.HTMLEditorKit; import javax.swing.text.html.HTML.Tag; import javax.swing.text.html.parser.ParserDelegator; import org.apache.log4j.Logger; public class TableParser extends ArrayList { static Logger logger = Logger.getLogger(TableParser.class); Stack s = new Stack(); /** * Process this reader. * @param f * @throws IOException */ public void parse(Reader f) throws IOException { this.clear(); new ParserDelegator().parse(f, parser, false); } private HTMLEditorKit.ParserCallback parser = new HTMLEditorKit.ParserCallback() { private boolean inTD; private String tdBuffer; public void handleError(String arg0, int arg1) { // System.out.println("Error "+arg0); // TODO Auto-generated method stub super.handleError(arg0, arg1); } public void handleText(char[] arg0, int arg1) { if (inTD){ tdBuffer += new String(arg0); } } public void handleStartTag(Tag tag, MutableAttributeSet arg1, int arg2) { if (tag == HTML.Tag.TABLE){ s.add(new TableParser.HTMLTable()); } else if (tag == HTML.Tag.TR){ s.add(new TableParser.HTMLRow()); } else if (tag == HTML.Tag.TD){ inTD = true; tdBuffer = ""; } } public void handleEndTag(Tag tag, int arg1) { if (tag == HTML.Tag.TABLE){ TableParser.HTMLTable T = (TableParser.HTMLTable)s.pop(); if (s.size() == 0){ TableParser.this.add(T); } else if (s.peek() instanceof HTMLRow){ ((HTMLRow)s.peek()).add(T); } else { logger.error("Need to be within nothing or a cell/row"); } } else if (tag == HTML.Tag.TR){ HTMLRow r = (HTMLRow)s.pop(); ((TableParser.HTMLTable)s.peek()).add(r); } else if (tag == HTML.Tag.TD){ if (inTD){ ((TableParser.HTMLRow)s.peek()).add(tdBuffer); inTD = false; } } } }; public class HTMLTable extends ArrayList{} public class HTMLRow extends ArrayList{} }

September 28, 2006 · Nigel Sim