Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] Exception on using VariableOneToOne annotation

Hello Kiran,

Yes, as the exception states, you have the "SourceTable.FORIENG_ID" mapped twice - the first being the foreignId mapping, and the second in the foreignEntity mapping. Only 1 can be writable; the others need to be set to read-only (or insertable+updatable =false ). Otherwise, should they ever be set differently, there is no way to tell which one
should be written to the database.

Best Regards,
Chris



On 26/11/2010 5:17 AM, Kiran Kumar Gubbi wrote:
Hi,

While on start of the application server I am getting the eclispe link
exception saying 'Only one may be defined as writable, all others must be
specified read-only.'. My table and the code detail is given below.

SourceTable - ID, FOREING_CLASS_TYPE , FORIENG_ID

TargetTable1 - T1_ID
TargetTable2 - T2_ID

The source table FORIENG_ID is foreing key to TagergetTable1.T1_ID and TargetTable2.T2_ID.


My DescriptorCustomizer detail is
public class SourceCustomizer implements DescriptorCustomizer
{
        public void customize( final ClassDescriptor descriptor )
	{
	    VariableOneToOneMapping variableOneToOneMapping = new
VariableOneToOneMapping();
	    variableOneToOneMapping.setAttributeName( "foreignEntity" );
	    variableOneToOneMapping.setReferenceClass( EntityInterface.class );
	    variableOneToOneMapping.setForeignQueryKeyName(
	    		"SourceTable.FORIENG_ID", "TargetTable1.T1_ID" );

	    variableOneToOneMapping.setForeignQueryKeyName(
	    		"SourceTable.FORIENG_ID", "TargetTable2.T2_ID" );

	    variableOneToOneMapping.setTypeFieldName( "SourceTable
.FOREING_CLASS_TYPE" );

	    // configure class indicators
	    variableOneToOneMapping.addClassIndicator( TargetTable1.class,
"TargetTable1" );
	    variableOneToOneMapping.addClassIndicator( TargetTable2 .class,
"TargetTable2" );

	    variableOneToOneMapping.dontUseIndirection();
	    variableOneToOneMapping.privateOwnedRelationship();

	    // add mapping to descriptor
	    descriptor.addMapping( variableOneToOneMapping );
	}
}

My entity has the VariableOntoOne mapping like the one mention below.


@Entity
@Table( name = "SourceTable" )
@Customizer( SourceCustomizer.class )
public class SourceTable {

@VariableOneToOne()
private EntityInterface foreignEntity;

@Column( name = "FORIENG_ID", nullable = false )
private Integer foreignId;

}

is there anything I am missing in this ?

Thanks,
Kiran


Back to the top