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,

I am able to persists the SourceEntity with no CacadeType and PrivateOwned
annotation as this was trying to insert Target table that I don't want. Now
I am having trouble while fetching the SourceEntity. The SourceEntity is
having null value for foreignEnity. 


Thanks,
Kiran


Kiran Kumar Gubbi wrote:
> 
> Hi Chris,
> 
> Thanks for your help. The issue was columnDefinition of the
> discriminatorColumn. I changed that to 'name', now it is fine. I have the
> same issue which James has explained. I am using two separate attributes
> one for FORIEGN_ID and other one for FOREING_CLASS_TYPE both insertable +
> updatable set to false. I hope there won't be any further issue on this.
> 
> Thanks,
> Kiran
> 
> 
> 
> 
> christopher delahunt wrote:
>> 
>> Hello Kiran,
>> 
>> Only potential problems I can see in your mapping is that the spelling 
>> of foreign is different in your join column from everywhere else.
>> 
>> The exception implies you are trying to execute a query - are there any 
>> problems persisting or reading in entities?  If the only problem you 
>> have is queries, the exception states queries over over VariableOneToOne 
>> mappings are not supported.  James answers a similar question in the 
>> Eclipselink forum at:
>> http://www.eclipse.org/forums/index.php?t=msg&goto=537838&#msg_537838
>> 
>> 
>> Regards,
>> Chris
>> 
>> On 30/11/2010 10:48 AM, Kiran Kumar Gubbi wrote:
>>> Hi Chirs,
>>> I have changed my code to use @VariableOneToOne annotation instead of
>>> Customizer. But I am getting the following exception.
>>>
>>> 'Mapping:
>>> [org.eclipse.persistence.mappings.VariableOneToOneMapping[foreignEntity]]
>>> 	at
>>> org.eclipse.persistence.exceptions.QueryException.cannotQueryAcrossAVariableOneToOneMapping(QueryException.java:405)'
>>>
>>> My annotation details are 
>>>
>>>        @VariableOneToOne( targetInterface = EntityInterface.class,
>>> 			discriminatorColumn =
>>> 				@DiscriminatorColumn(
>>> 						columnDefinition = "FOREING_CLASS_TYPE",
>>> 						discriminatorType = DiscriminatorType.STRING ),
>>> 	        discriminatorClasses = {
>>>         		@DiscriminatorClass( discriminator = "TargetTable1", value =
>>> TargetTable1.class ),
>>>         		@DiscriminatorClass( discriminator = "TargetTable2", value =
>>> TargetTable2.class )
>>>            },
>>>            fetch = FetchType.LAZY
>>> 	)
>>> 	@JoinColumn( name = "FORIENG_ID", referencedColumnName = "id" )
>>> 	@PrivateOwned
>>> 	private EntityInterface foreignEntity;
>>>
>>> I hope there might be some error in my annotation.
>>>
>>> Thanks,
>>> Kiran
>>>
>>>
>>>
>>> christopher delahunt wrote:
>>>   
>>>> Hello Kiran,
>>>>
>>>> You have the foreignEntity attribute mapped twice; once when you add 
>>>> the  @VariableOneToOne() annotation, and the second is when you add the 
>>>> customizer code to create the new VariableOneToOneMapping. 
>>>> Since the annotation has nothing defined, it will use the default
>>>> fields 
>>>> - FOREIGNENTITY_ID for the foreign key, and DTYPE for the type field. 
>>>>
>>>> Map the column entirely through annotations, or look up the mapping on 
>>>> the descriptor in the customizer instead of creating a new one.  ie 
>>>> descriptor.getMapping("foreignEntity")
>>>>
>>>> Regards,
>>>> Chris
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> On 29/11/2010 5:11 AM, Kiran Kumar Gubbi wrote:
>>>>     
>>>>> 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
>>>>>>
>>>>>>
>>>>>>     
>>>>>>         
>>>>>   
>>>>>       
>>>> _______________________________________________
>>>> 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-tp30308910p30348159.html
Sent from the EclipseLink - Users mailing list archive at Nabble.com.



Back to the top