Skip to main content

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

Hi Chris,

After correcting the customizer I am not getting exception on server start
up. But while on page loading I am getting ' java.sql.SQLException:
ORA-00904: "T1"."DTYPE": invalid identifier ' exception. My source class is
having the foreignClassType and foreignId which are set insertable +
updatable as 'false'  (This fields are very much required as our JPQL uses
this fields in where clause). But when I see in the server log it seems the
sql is having two new column t1.FOREIGNENTITY_ID , t1.DTYPE  which I have
not defined in my entity. 

To make further clear I am giving my lates entity and customizer details

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

@Column( name = "SOURCE_ID", nullable = false, unique = true )
private Integer id;

 @VariableOneToOne()
 private EntityInterface foreignEntity;

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

 @Column( name = "FOREING_CLASS_TYPE", nullable = false, insertable = false,
updatable = false )
 private String foreignClassType;

// atttribute setter and getter method 	
	
 }
 
 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",
"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 );
 	}
 }

Any suggestion is very helpfull. 

Thanks,
Kiran



christopher delahunt wrote:
> 
> yes, that was only part of the problem.  The other part is you are using 
> the setForeignQueryKeyName incorrectly. 
> The method signature is addForeignQueryKeyName(String 
> sourceForeignKeyFieldName, String targetQueryKeyName)
> where as you are passing in two fields - the second parameter should be 
> a query key, not a database field.  It should look something like:
>   variableOneToOneMapping.setForeignQueryKeyName( 
> "SourceTable.FORIENG_ID", "queryKeyName");
> 
> The "queryKeyName" must be a query key  in the target variable 
> descriptor that will be mapped to the primary key in the hard 
> implementation descriptors.
> So it will need to be mapped to "TargetTable1.T1_ID" and 
> "TargetTable2.T2_ID" depending on the concrete class the discriminator 
> indicates. 
> 
> Variable mappings are described at:
> http://wiki.eclipse.org/Configuring_a_Relational_Variable_One-to-One_Mapping_(ELUG)
> 
> Best Regards,
> Chris
> 
> On 26/11/2010 9:47 AM, Kiran Kumar wrote:
>> Hello Chris,
>>
>> Even after removing 'foreignId' attribute from the 'SourceEntity' still
>> getting the exception saying 'Only one may be defined as writable, all
>> others must be specified read-only'. I have a doubt is it because of
>> 'setForeignQueryKeyName' in SourceCustomizer class using twice to set
>> the foreign_id to the primary key of TargetTable1 and TargetTable2.
>>
>> Thanks,
>> Kiran
>>
>>
>>
>> -----Original Message-----
>> From: eclipselink-users-bounces@xxxxxxxxxxx
>> [mailto:eclipselink-users-bounces@xxxxxxxxxxx] On Behalf Of Christopher
>> Delahunt
>> Sent: 26 November 2010 13:19
>> To: EclipseLink User Discussions
>> Subject: Re: [eclipselink-users] Exception on using
>> VariableOneToOneannotation
>>
>> 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
>>>  
>>>   
>>>     
>> _______________________________________________
>> eclipselink-users mailing list
>> eclipselink-users@xxxxxxxxxxx
>> https://dev.eclipse.org/mailman/listinfo/eclipselink-users
>>   
> 
> _______________________________________________
> eclipselink-users mailing list
> eclipselink-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/eclipselink-users
> 
> 

-- 
View this message in context: http://old.nabble.com/Exception-on-using-VariableOneToOne-annotation-tp30308910p30329033.html
Sent from the EclipseLink - Users mailing list archive at Nabble.com.



Back to the top