You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by Krzysztof <ya...@gmail.com> on 2011/05/19 11:44:57 UTC

ManyToOne "cannot be mapped without stringifying the oid of the related object to a string column." in a unidirectional relationship.

Hello,

I have stumbled at the problem I thought was solved some time ago: with a
ManyToOne field which references class with a 2nd level composite id (its id
includes classId of other class in the class graph) I got following
exception during schema creation:

 <openjpa-2.1.0-r422266:1071316 fatal user error>
org.apache.openjpa.persistence.ArgumentException:
"TimeSeriesResult.fTimeSeries" cannot be mapped without stringifying the oid
of the related object to a string column.  The related type is unmapped and
its "TimeSeries.fSource" primary key field does not use a simple mapping.
  2         at
org.apache.openjpa.jdbc.meta.strats.RelationStrategies.mapPrimaryKey(RelationStrategies.java:169)
  3         at
org.apache.openjpa.jdbc.meta.strats.RelationStrategies.newUnmappedPCTemplateColumns(RelationStrategies.java:143)
  4         at
org.apache.openjpa.jdbc.meta.strats.RelationStrategies.mapRelationToUnmappedPC(RelationStrategies.java:119)
  5         at
org.apache.openjpa.jdbc.meta.strats.RelationStrategies.mapRelationToUnmappedPC(RelationStrategies.java:110)
  6         at
org.apache.openjpa.jdbc.meta.strats.RelationFieldStrategy.map(RelationFieldStrategy.java:175)
  7         at
org.apache.openjpa.jdbc.meta.FieldMapping.setStrategy(FieldMapping.java:146)
  8         at
org.apache.openjpa.jdbc.meta.RuntimeStrategyInstaller.installStrategy(RuntimeStrategyInstaller.java:82)
  9         at
org.apache.openjpa.jdbc.meta.FieldMapping.resolveMapping(FieldMapping.java:496)
 10         at
org.apache.openjpa.jdbc.meta.FieldMapping.resolve(FieldMapping.java:461)
 11         at
org.apache.openjpa.jdbc.meta.ClassMapping.resolveMapping(ClassMapping.java:854)
 12         at
org.apache.openjpa.meta.ClassMetaData.resolve(ClassMetaData.java:1801)
 13         at
org.apache.openjpa.meta.MetaDataRepository.processBuffer(MetaDataRepository.java:822)
 14         at
org.apache.openjpa.meta.MetaDataRepository.resolveMapping(MetaDataRepository.java:777)
 15         at
org.apache.openjpa.meta.MetaDataRepository.resolve(MetaDataRepository.java:657)
 16         at
org.apache.openjpa.meta.MetaDataRepository.getMetaDataInternal(MetaDataRepository.java:411)
 17         at
org.apache.openjpa.meta.MetaDataRepository.getMetaData(MetaDataRepository.java:384)
 18         at
org.apache.openjpa.jdbc.meta.MappingRepository.getMapping(MappingRepository.java:355)
 19         at
org.apache.openjpa.jdbc.meta.MappingTool.getMapping(MappingTool.java:681)
 20         at
org.apache.openjpa.jdbc.meta.MappingTool.buildSchema(MappingTool.java:753)
 21         at
org.apache.openjpa.jdbc.meta.MappingTool.run(MappingTool.java:651)
 22         at
org.apache.openjpa.jdbc.kernel.JDBCBrokerFactory.synchronizeMappings(JDBCBrokerFactory.java:154)
 23         at
org.apache.openjpa.jdbc.kernel.JDBCBrokerFactory.synchronizeMappings(JDBCBrokerFactory.java:164)
 24         at
org.apache.openjpa.jdbc.kernel.JDBCBrokerFactory.newBrokerImpl(JDBCBrokerFactory.java:122) 
 25         at
org.apache.openjpa.kernel.AbstractBrokerFactory.newBroker(AbstractBrokerFactory.java:210)
 26         at
org.apache.openjpa.kernel.DelegatingBrokerFactory.newBroker(DelegatingBrokerFactory.java:156) 
 27         at
org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:227)
 28         at
org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:154)
 29         at
org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:60)


This is a show-stopper for me. Are there any workarounds for this??

fTimeSeries is the unidirectional reference, so fSource must not know about
it.
fSource has composite identity class obviously so has TimeSeries that
expands its identity on Source's one. This works. TimeSeriesResult wants to
reference TimeSeries.

I tried providing composite identity fields using JoinColumns but at no
avail:

<TimeSeriesResult.java>
@ManyToOne(fetch=FetchType.LAZY,optional=false,targetEntity=TimeSeries.class)
@JoinColumns({
		@JoinColumn(name="catalogId", referencedColumnName = "catalogId", nullable
= false, updatable = false)
		,@JoinColumn(name="sourceId", referencedColumnName = "sourceId", nullable
= false, updatable = false)
		,@JoinColumn(name="fTimeSeriesType",referencedColumnName
="fTimeSeriesType", nullable = false, updatable = false)}
		)
	@ForeignKey //does not change anything
	protected TimeSeries fTimeSeries;
</>

 I think this problem goes away if the reference is bidirectional and
mappedBy can be used, but how to use it in a unidirectional relationship?

I was thinking that switching from @ClassId annotation to @EmbeddedId and
@MapsId might help but this would trigger many changes in already tested
code that should not be affected by this link.

Any help appreciated. Should I create a jira for that?

Cheers,
Krzysztof

--
View this message in context: http://openjpa.208410.n2.nabble.com/ManyToOne-cannot-be-mapped-without-stringifying-the-oid-of-the-related-object-to-a-string-column-in--tp6381267p6381267.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.