| I need some help on adding StructConverters programatically. [message #889858] |
Tue, 19 June 2012 21:32  |
Sumitro Palit Messages: 2 Registered: June 2012 |
Junior Member |
|
|
// -----------
// Preamble
//------------
In our system, we make heavy use of user defined types. Most tables have multiple fields that are user defined types , some of which could be repeated within a table.
eg. Table_1 might have columns of type FOO1, FOO2, FOO3 and another FOO3. Table_2 might have columns of type FOO1, FOO2 and FOO4.
Our goal is to use StructConverters to do the mapping and also keep the configuration of the mapping (annotations) least intrusive. Ideally I would do this programatically ( or through sessions.xml if that is easier but prefer using a pure JPA soulution).
We are using EclipseLink 2.3.2 in Eclipse Indigo + maven to run from command line.
//----------
// Question
//----------
I added my own SessionCustomizer and called addStructConverter() on the session (DataBasePlatform).
public class MySessionCustomizer extends SessionCustomizer {
public void customize(Session session) {
DatabasePlatform dp = (DatabasePlatform) session
.getDatasourcePlatform();
dp.addStructConverter(new Foo1Converter());
dp.addStructConverter(new Foo2Converter());
}
}
My understanding was that this approach would work if "public String getStructName()" and "public Class getJavaType()" are implemented on Foo1Converter & Foo2Converter - so no annotations would be necessary at the individual getter methods. However this approach is not working.
I am getting errors like:
Exception Description: The object [Foo1 [x=217.8., basis=std, description=null]], of class [class com.test.jpa.usertype.Foo1], from mapping [org.eclipse.persistence.mappings.DirectToFieldMapping[foo1-->TABLE1.FOO1]] with descriptor [RelationalDescriptor(com.test.jpa.Table1 --> [DatabaseTable(TABLE1)])], could not be converted to [class [B].
at org.eclipse.persistence.exceptions.ConversionException.couldNotBeConverted(ConversionException.java:71)
The documentation for addStructConverter() says "Call this method within your EclipseLink session (server or database) prior to the session login ".
How do we achieve this programatically or do I need to use a sessions.xml configuration.
Does anyone have an example project (eclipse or maven) that uses multiple structconverters that way we are trying to use them.
//------------
// Note that we have used annotations to make the converters work but prefer to add these transparently via a session customizer class.
//------------
------------------------------------------------
So far, I have been able to make it work by using StructConverters/StructConverter/Convert annotations, ex:
// on any entity
@StructConverters(value = {
@StructConverter(name = "Foo1Converter", converter = "com.test.jpa.converters.Foo1Converter"),
@StructConverter(name = "Foo2Converter", converter = "com.test.jpa.converters.Foo2Converter") })
@Convert(value = "Foo1Converter")
@Column(name = "FOO1")
public Foo1 getFoo1() {
return this.foo1;
}
@Convert(value = "Foo2Converter")
@Column(name = "FOO2")
public Foo2 getFoo2() {
return this.foo2;
}
This works, but has an issue in Eclipse (Indigo).
Eclipse shows errors on @Convert(value = "Foo1Converter") as it thinks it can't find the named converters : "The specified converter "Foo1Converter" for mapping "foo1" cannot be resolved"
Everything however compiles and runs from eclipse or from the command line using maven. So this is more of a nuisance than anything else.
If we add a single @StructConverter then eclipse is happy, but then we can't seem to add multiple @StructConverter except in a @StructConverters collection. So we have to live with the errors.
Has anyone else seen such issues on Eclipse?
------------------------------------------------
[Updated on: Wed, 20 June 2012 11:39] Report message to a moderator
|
|
|