Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 391251 - Transformation mapping silently ignores @Column annotation if it is outside @WriteTransformer annotation
Summary: Transformation mapping silently ignores @Column annotation if it is outside @...
Status: RESOLVED FIXED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: All All
: P2 normal (vote)
Target Milestone: ---   Edit
Assignee: Nobody - feel free to take it CLA
QA Contact:
URL:
Whiteboard: submitted_patch
Keywords:
Depends on:
Blocks:
 
Reported: 2012-10-05 12:22 EDT by Mythily Parthasarathy CLA
Modified: 2022-06-09 10:25 EDT (History)
5 users (show)

See Also:


Attachments
Proposed fix for this bug. (5.94 KB, patch)
2013-01-17 00:12 EST, Mythily Parthasarathy CLA
david.minsky: iplog+
Details | Diff
Modified patch and testcase (11.43 KB, patch)
2013-02-06 21:50 EST, Mythily Parthasarathy CLA
david.minsky: iplog+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Mythily Parthasarathy CLA 2012-10-05 12:22:25 EDT
Transformation mapping ignores the @Column annotation applied to the field if the @Column is specified outside the @WriteTransformer annotation.  

For instance, @Column annotation gets ignored below :
@Entity 
@Table(name="LOCATION_MAP") 
public class LocationMap implements Serializable { 
 
   @Transformation
   @ReadTransformer(IPAttributeTransformer.class) 
   @WriteTransformer(IPAttributeTransformer.class) 
   @Column(name="IP_ADDR") 
   protected String ipAddr; ... 
}
Comment 1 Mythily Parthasarathy CLA 2012-10-05 12:46:40 EDT
Working on submitting a fix and for this issue.
Comment 2 Tom Ware CLA 2012-11-16 13:31:28 EST
Setting target and priority.  See the following page for the meanings of these fields:

http://wiki.eclipse.org/EclipseLink/Development/Bugs/Guidelines

Community: Please vote for this bug if it is important to you.  Votes are one of the main criteria we use to determine which bugs to fix next.
Comment 3 Mythily Parthasarathy CLA 2013-01-17 00:12:05 EST
Created attachment 225744 [details]
Proposed fix for this bug.

Proposed Fix : To throw a ValidationException in above case.
With current fix, if an entity "Employee" contains :
      @WriteTransformer(method="getStime")
      @Column(name="TIME")
      private Time stime; 

the exception raised will be :

Exception Description: Predeployment of PersistenceUnit [default] failed.
Internal Exception: Exception [EclipseLink-7356] (Eclipse Persistence Services - 2.5.0.qualifier): org.eclipse.persistence.exceptions.ValidationException
Exception Description: Entity class [class bug.Employee] must specify @Column annotation within @WriteTransformer annotation for attribute stime.

Tests added : No.  Attempted adding a test, but this will cause predeployment errors and the persistence unit will not load.  Adding an automated test will break the tests, hence not added.

Tests done : Manual testing for negative and positive case as below
   Negative case (Error seen) -        
      @WriteTransformer(method="getStime")

      @Column(name="TIME")
      private Time stime; 

  Positive case (No error)-
      @WriteTransformer(method="getStime", column=@Column(name="TIME")) 
 
Other tests :

     ant -f antbuild.xml test-jpa : got 100% success.
Comment 4 Guy Pelletier CLA 2013-01-17 12:00:19 EST
Out of fear of being too restrictive (when we could support both configurations) and perhaps breaking existing users, I think it is best to look for the second @Column definition and use it if it is defined.

I small change to the WriteTransformer constructor would do this, that is:

/**
 * INTERNAL:
 * Used for annotation loading.
 */
public WriteTransformerMetadata(MetadataAnnotation writeTransformer, MetadataAccessor accessor) {
  super(writeTransformer, accessor);
        
  Object column = writeTransformer.getAttribute("column");
        
  if (column != null) {
    m_column = new ColumnMetadata((MetadataAnnotation) column, accessor);
  } else {
    m_column = new ColumnMetadata(accessor.getAccessibleObject().getAnnotation(MetadataConstants.JPA_COLUMN), accessor);
  }
}

This would then allow users both options to specifying the column.
Comment 5 Mythily Parthasarathy CLA 2013-01-17 12:18:34 EST
Thank you for the feedback.  Will re-submit modified patch with the feedback incorporated.
Comment 6 Mythily Parthasarathy CLA 2013-02-06 21:50:06 EST
Created attachment 226671 [details]
Modified patch and testcase

Sorry for the delay.  Uploaded new proposed patch with suggested change from Guy Pelletier and testcase added to AdvancedJPAJunitTest.  JPA tests passed.  Thank you for reviewing.
Comment 7 Mythily Parthasarathy CLA 2013-02-07 18:36:47 EST
Problem description: @Column annotation was being ignored silently in WriteTransformerMetadata.  Only column attribute was considered. 
 
Fix Description:  In org.eclipse.persistence.internal.jpa.metadata.transformers.WriteTransformerMetadata contructor - WriteTransformerMetadata(MetadataAnnotation writeTransformer, MetadataAccessor accessor), only column attribute is read.  Changed this as below -
if column attribute provided
   use this attribute
else
   if column annotation is provided, use the column annotation.   

Tests added : 
In AdvancedJunitJPATest, added a test - testTransformationMappingWithColumnAnnotation to test @WriteTransformer annotation with @Column annotation specified outside.
Other case with column attribute specified already exists.
 
Testing done :
"ant -f antbuild.xml test-jpa" produced 100% success
Comment 8 David Minsky CLA 2013-02-08 16:56:14 EST
Fixed in master (2.5) at: 0f71573e3f226b56f9850e3714e151e6a67e4404
2.4.x branch checkin pending.
Comment 9 David Minsky CLA 2013-02-08 18:44:15 EST
Checked into 2.4.x branch (2.4.2) at: ec3d7e7949308ecf7c3ec5c041ca64d3530f39a5
Comment 10 Eclipse Webmaster CLA 2022-06-09 10:25:04 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink