Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » @Transformation - Unknown state or association field
@Transformation - Unknown state or association field [message #386019] Thu, 19 March 2009 13:22 Go to next message
Josh Davis is currently offline Josh DavisFriend
Messages: 10
Registered: July 2009
Junior Member
I have a class that uses a Transformation mapping for the IP address
field. The IP address is the string dot notation in the class, but is a
long integer in the database. My entity class looks like this:

@Entity
@Table(name="LOCATION_MAP")
public class LocationMap implements Serializable {
@Transformation
@ReadTransformer(IPAttributeTransformer.class)
@WriteTransformer(IPAttributeTransformer.class)
@Column(name="IP_ADDR")
protected String ipAddr;
...
}

IPAttributeTransformer is a class that implements both
org.eclipse.persistence.mappings.transformers.AttributeTrans fomer and
org.eclipse.persistence.mappings.transformers.FieldTransform er.

When I attempt to execute the query, "select location.ipAddr from
LocationMap location", it gives me the error Error compiling the query
(select location.ipAddr from LocationMap location), line 1, column 16:
unknown state or association field (ipAddr) of class
(com.example.LocationMap).

If I comment out the @Transformation, @ReadTransformer, and
@WriteTransformer annotations, then I don't get the error, but of course I
also don't get the transformed IP address.

If I change my query to "select location from locationMap location",
selecting the whole object instead of just the one field, I get a
different error.

Internal Exception: java.sql.SQLException: ORA-00904: "IPADDR": invalid
identifier

Error Code: 904
Call: SELECT LOCATION_ID AS LOCATION_ID1, CREATE_TIME AS CREATE_TIME2,
UPDATE_TIME AS UPDATE_TIME3, COUNTRY_ID AS COUNTRY_ID4, STATE_ID AS
STATE_ID5, CITY_ID AS CITY_ID6, ipAddr AS ipAddr7

The column name should be IP_ADDR, but it is inserting the attribute name
instead.
Re: @Transformation - Unknown state or association field [message #386044 is a reply to message #386019] Thu, 19 March 2009 14:31 Go to previous messageGo to next message
Gordon Yorke is currently offline Gordon YorkeFriend
Messages: 77
Registered: July 2009
Member
It seems like there may be an issue with the annotation processing. Try
removing the @Transformation annotation as it is not required once the
@WriteTransformation and/or @ReadTransformation annotations are specified.
Please file a bug.
Re: @Transformation - Unknown state or association field [message #386045 is a reply to message #386019] Thu, 19 March 2009 14:32 Go to previous messageGo to next message
Gordon Yorke is currently offline Gordon YorkeFriend
Messages: 77
Registered: July 2009
Member
Also what does the SQL look like when you perform a em.find() ?
Re: @Transformation - Unknown state or association field [message #386046 is a reply to message #386044] Thu, 19 March 2009 14:47 Go to previous messageGo to next message
Josh Davis is currently offline Josh DavisFriend
Messages: 10
Registered: July 2009
Junior Member
I just found the answer. Instead of this:

@Entity
@Table(name="LOCATION_MAP")
public
class LocationMap implements Serializable {

@Transformation
@ReadTransformer(IPAttributeTransformer.class)
@WriteTransformer(IPAttributeTransformer.class) @Column(name="IP_ADDR")
protected String ipAddr; ...

}

It needs to be this:
@Entity
@Table(name="LOCATION_MAP")
public class LocationMap implements Serializable {

@Transformation
@ReadTransformer(IPAttributeTransformer.class)
@WriteTransformer(IPAttributeTransformer.class,
column=@Column(name="IP_ADDR"))
protected String ipAddr;
...

}

Transformation mapping ignores the @Column annotation applied to the
field. The @Column annotation must appear inside the @WriteTranformer
annotation.

I already filed a bug last week. I'll go close it now.
Re: @Transformation - Unknown state or association field [message #386047 is a reply to message #386046] Thu, 19 March 2009 14:54 Go to previous messageGo to next message
Gordon Yorke is currently offline Gordon YorkeFriend
Messages: 77
Registered: July 2009
Member
Leave the bug open but please update it. This is a usability issue that
should be addressed.
Re: @Transformation - Unknown state or association field [message #386048 is a reply to message #386047] Thu, 19 March 2009 15:46 Go to previous messageGo to next message
Josh Davis is currently offline Josh DavisFriend
Messages: 10
Registered: July 2009
Junior Member
I left it open as a doc bug. I'd be happy with example code for each
mapping type showing how to use annotations. I looked for such, but
couldn't find it.

I had filed the bug on Oracle BugDB under TopLink, bug number 8339175.
Re: @Transformation - Unknown state or association field [message #386049 is a reply to message #386048] Thu, 19 March 2009 19:06 Go to previous messageGo to next message
Josh Davis is currently offline Josh DavisFriend
Messages: 10
Registered: July 2009
Junior Member
Correction, it still isn't fixed.

My change made it so that "select location from Location location" works
now, but "select location.ipAddr from Location location" still gives
Unknown state or association.
Re: @Transformation - Unknown state or association field [message #386056 is a reply to message #386049] Mon, 23 March 2009 13:42 Go to previous message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

The issue is that because TransformationMappings can use multiple columns
they are currently not supported in queries. Feel free to log a bug for
this, however in general you should not use a @Transformation if you only
have a single column, just use a Converter (@Convert), it is much simpler
than using a TransformationMapping. A TransformationMapping should only
be use if you are mapping multiple columns to a single attribute, or
mapping a column without an attribute.

---
James
http://www.nabble.com/EclipseLink---Users-f26658.html


James : Wiki : Book : Blog : Twitter
Previous Topic:EclipseLink 1.1.0
Next Topic:weaving or not
Goto Forum:
  


Current Time: Sat Dec 20 14:39:26 GMT 2014

Powered by FUDForum. Page generated in 0.02044 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software