Blog Archives

January 5th, 2010
4:56 pm
@ManyToMany issues with Eclipselink 1.1.2

Posted under JPA
Tags , , , ,

I found a number of issues when configuring a many to many relationship, but eventually found a working solution.

1/  This example for a many to many uses referencedColumnName when it does not need to – it was a hangover from an example using multiple join columns. If you do this with Eclipselink 1.1.2 and Oracle (in my case XE 10g), the columns are created with data types of varchar2(255) instead of the default of number(19)  :-

      @ManyToMany
      @JoinTable(name="AppUserRole",
                 joinColumns =@JoinColumn(name="AppUserID",
                                          referencedColumnName="AppUserID"),
                 inverseJoinColumns=@JoinColumn(name="AppRoleID",
                                          referencedColumnName="AppRoleID”))

The referencedColumnName attribute is the cause of this issue. Leaving it out causes correct column types. It is only needed for multiple column joins (which break anyway see 2/), and so should not be used. This therefore works correctly and is the recommended format to use  :-

      @ManyToMany
      @JoinTable(name="AppUserRole",
                 joinColumns =@JoinColumn(name="AppUserID"),
                 inverseJoinColumns=@JoinColumn(name="AppRoleID"))

2/ Using a many to many as in 1/ but with multiple join columns causes eclipselink bug 300485. (Although listed as a one to many bug it also happens with many to many). This is not due to be fixed until eclipselink 2.1. The bug gives a query parameter not found error for an internally generated query used when eclipselink lazily loads a relationship collection.

3/ Leaving out the @JoinTable and only having the @ManyToMany annotation works ok, but gives an XML column name resolution error from eclipse for one of the join columns. This is purely an ‘invalid validation’ however, as the code runs fine against a database created from it.

4/ using the xml annotations in orm.xml along with just an @ManyToMany annotation in the code works fine, but you do get some validation errors from Eclipse as the validation does not appear to merge the annotations and xml correctly when validating :-

<entity>
  <attributes>
   <many-to-many name="appRoles">
    <join-table name="AppUserRole">
     <join-column name="AppUserID" column-definition="number(19)"/>
     <inverse-join-column name="AppRoleID" column-definition="number(19)"/>
    </join-table>
   </many-to-many>
  </attributes>
 </entity>

This would be the preferred route if anything database specific  was needed, such as the column-definition attributes for Oracle in the example.  The “@ManyToMany” annotation on the entity may be superfluous in this case but is a helpful label. A comment in the code that there are overrides in orm.xml would be helpful. The above fragment was tested but without the column-definition attributes on the columns – these are shown as examples of how to add database specific column definitions without having to pollute the code with them via annotations.

The intention here would be to use xml in conjunction with annotations, with annotations used for all the standard metadata. Different versions of orm.xml and persistence.xml could then be swapped in and out for different back end databases, keeping the code standard. The same approach has been advocated to permit using Oracle sequences here.

No Comments »

December 18th, 2009
7:45 pm
Installing the Glassfish Eclipse Plugin

Posted under Eclipse
Tags , ,

The process is a workaround for this eclipse bug, which seems to have been around for some time.

  1. In Eclipse, enter Help/Add new software
  2. Click the Add button to add a new update site, and enter the url https://ajax.dev.java.net/eclipse (I have also used http://ajax.dev.java.net/eclipse instead as suggested by other forums, but some users state that this does not work).
  3. Wait for the screen to populate (this may take some time), then select “Glassfish Java EE 5 and Java EE 6 support” and hit next
  4. Proceed with the installation as directed by the wizard.

No Comments »

December 18th, 2009
5:38 pm
Eclipse JPA out of synch with newly fetched CVS project

Posted under Eclipse
Tags , ,

I had this issue when deleting and refetching a project from CVS into Eclipse.

It reported that it was unable to resolve a number of the persistence classes such as EntityManager and EntityManagerFactory, even though the libraries and the imports were all present correctly.

This was solved by removing the Java persistence facet from the project facets page, applying the change, and adding persistence back and reconfiguring it. The problem then disappeared.

This was one of several Eclipse ‘gotchas’ I have found where Eclipse reports errors which do not exist. Often, a reconfigure such as the above, or a restart/reload will sort it.

No Comments »

December 18th, 2009
5:25 pm
Eclipse error “Class is listed in persistence.xml but not mapped”

Posted under Eclipse
Tags , , ,

Sometimes eclipse lists the following error in the problem view :-

Class xxx is listed in the persistence.xml file but is not mapped

This appears to be a synchronisation problem within Eclipse, as deleting the classes from persistence.xml and then adding them back by browsing with Eclipse’s own persistence.xml editor eliminates the problem, even though the resulting file is identical. Validating the original file did not solve the problem.

Even with the error listed, projects still run and build successfully, so the problem is not serious.

I have also had other cases where Eclipse has whinged about a perfectly good persistence.xml, and have in general just lived with it as it is not serious.

This is an important issue to be aware of though to prevent much head scratching when such a problem is believed to be a real error and is not!

No Comments »

December 18th, 2009
5:07 pm
CVSNT – cvslock.exe crashes on new repository add

Posted under CVS
Tags , , ,

cvslock.exe sometimes crashes with the following pair of event log messages :-

  1. Failed to bind listening socket: Only one usage of each socket address (protocol/network address/port) is normally permitted.
  2. Faulting application cvslock.exe, version 0.0.0.0, faulting module advapi32.dll…

Initially I thought this was due to not adding it as a firewall/antivirus exception, but the error still appears to happen the first time a repository is created and brought up/reconfigured. The 2 errors appear to be related – the socket error may be due to cvslock being started twice in error (indeed, this may be the cause of the other error too.)

Once the repository configuration is up and stable, the error does not seem to occur.

When the error occurs, a systray icon for cvslock appears, and selecting the debug listing menu option for the tray icon displays the error “no ipv6 address found for host” in a command window.

I tried stopping the services, creating a new repository (which succeeds), and then starting the services. The cvslock service refuses to start, and the tray icon appears as above. After a few seconds, the tray icon disappears, and the service can be started as normal.

This does appear to be a cvslock issue related to new repository creation. As the workaround is straightforward, and operation appears stable after that, the bug appears to be a minor one.

No Comments »

December 18th, 2009
4:52 pm
Eclipse Glassfish Plugin loses sync with Glassfish start/stop state

Posted under Eclipse
Tags , , ,

This appears to be an issue if you start Glassfish (2.1.1) outside of Eclipse (3.5.1) – Eclipse does not then always sync with it properly. It may try to start it when it is already started and fail, then fail to publish/run projects correctly.
There is an old bug logged on this here. It claims to have been resolved, but the resolution does not appear to be seamless – it appears that Eclipse cannot fully integrate with an externally started Glassfish.

I expect this to be sorted with Glassfish V3 as this is fully OSGI compliant.
In the meantime, the answer seems to be to allow Eclipse to fully control Glassfish, i.e. start and stop it itself, and to not start Glassfish externally when using Eclipse.

No Comments »

December 18th, 2009
3:06 pm
Toad fails to connect with ORA-12154 on Windows 7 64 bit

Posted under 64 Bit
Tags , , ,

I hit this problem trying to connect to a local Oracle XE 10.2.0.1 database.
The problem is due to a bug in Oracle’s networking layer. It cannot parse program locations containing parentheses, and by default Toad installs to “Program Files (x86)” which causes the bug.

More details on OTN here.

The fault is designated Bug 3807408, and whilst there is an Oracle patch for it, the patch is not available for Oracle XE.

The easy way around the problem is just to install TOAD in “Program Files” rather than “Program Files (x86)”. The different directories are purely to aid in distinguishing 32 bit applications from 64 bit ones – it does not matter where applications are installed.

I removed and reinstalled TOAD in “Program Files” and this completely eliminated the problem. The problem would also apply to other applications which access Oracle, so worth bearing in mind.

No Comments »

December 18th, 2009
12:30 pm
Tomcat with JPA Persistence jar signing issue

Posted under Tomcat
Tags , , ,

I hit this when deploying  an Eclipselink 1.1 web application to Tomcat 6.0.24, when trying to place all the persistence jars in <Tomcat Home>\lib

The app worked fine when including its own copy of the jars under WEB-INF\lib, but moving them to <Tomcat Home>\lib gave the following error :-

java.lang.SecurityException: class “javax.persistence.Persistence”‘s signer information does not match signer information of other classes in the same package

I checked all the other (non eclipselink) libraries present and could not see a clash. This post appears to shed some light, indicating that it is perhaps a mismatch of jar signing in the Eclipsink libraries.
However, it is strange that it works fine with the libraries deployed with the application rather than under Tomcat.

As Tomcat does not provide its own JPA support, I decided I was quite happy to deploy the libraries with the web app as that works fine, and to leave the issue unresolved.

No Comments »

December 1st, 2009
9:35 am
ICEfaces 1.8.1 app fails to run default sample page

Posted under JSF
Tags , , , ,

I created a simple test web app using ICEfaces, including the test/sample page that the plugin creates for you by default. When running the app on Glassfish, the error “Object doesn’t support this property or method” occurs and the page fails to load correctly. The same application works in Tomcat.

The issue turns out to be due to a single extra space in web.xml. The Eclipse code has an extra trailing space in the url pattern for the Persistent Faces Servlet mapping as follows :-

Broken Version with trailing space after the * – works on Tomcat 6, fails on GlassFish 2.1

<url-pattern>/xmlhttp/* </url-pattern>

Working Version without trailing space – works on both

<url-pattern>/xmlhttp/*</url-pattern>

The effect of the extra trailing space appears to be that GlassFish 2.1 does not obey the servlet mapping for this url pattern. Tomcat is not tripped up by the trailing space. An extra hazard for the unwary in Eclipse (Galileo) is that if you use the XML editor to edit web.xml, it hides the trailing space if it is present, so you could miss it even if you were aware of the potential issue. The text editor shows the space correctly.

My original post on this in the ICEfaces forums is here. This problem has been fixed in 1.8.2 – the bug tracker entry for the problem is here. Note that upgrading to 1.8.2 will not apply the fix to existing projects in Eclipse, only to new ones. For existing projects, you need to remove the extra space in web.xml manually.

No Comments »

November 30th, 2009
12:59 pm
Eclipse errors on startup

Posted under Eclipse
Tags ,

Sometimes Eclipse fails to start correctly, refusing to open various views. The following error is typical :-

“Eclipse Galileo Could not open the editor: The editor class could not be instantiated.
This usually indicates a missing no-arg constructor or that the editor’s class name was mistyped in plugin.xml.”

There can be a number of causes, but this suggestion may fix it (worked for me) :-http://www.eclipse.org/forums/index.php?t=msg&goto=443229&S=c7e035ee876b3f197920eb538fdca5c6#msg_443229

The fix is to delete the following file :-
.metadata/.plugins/org.eclipse.jdt.core/variablesAndContainers.dat 

The problem is said to be related to a bug in the data tools plugin. It should be be fixed in version 1.7.2 of the plugin.

No Comments »