openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Patrick Linskey" <plins...@gmail.com>
Subject Re: Self Bidirectional relation trouble
Date Tue, 19 Jun 2007 22:00:44 GMT
> Am I missing something? I think that it isn't recognizing the field owner as
> a persistence capable entity.
> If I wasn't clear enough please let me know.

What are the sub-types of Place? TABLE_PER_CLASS means that there is
one table per concrete subtype. OpenJPA is throwing that exception
because the relation is to an abstract type, which means that the
class is not mapped per the default behavior for TABLE_PER_CLASS.

If you happen to only have one subtype for Place, then you can get
around this simply by changing your relation to be to the concrete
subtype, or by specifying the @ElementType annotation to narrow the
type of the relation.

Otherwise, you can tell OpenJPA to use a more inefficient mapping, in
which the object IDs will need to be serialized into the database,
instead of being regular joins.

Another easy solution is to make Place non-abstract.

You might want to take a look at
http://openjpa.apache.org/docs/latest/manual/manual.html#ref_guide_mapping_limits_tpc
for more information about the limitations of TABLE_PER_CLASS
mappings.

-Patrick

On 6/19/07, Mariano <albolocura@gmail.com> wrote:
> Hi all! I've decided migrating from TopLink to OJPA, and I'm having a
> trouble with the following code:
>
>
> @Entity
> @Inheritance
> (strategy = InheritanceType.TABLE_PER_CLASS)
> abstract public class Place {
>     .
>     .
>     .
>
>     @OneToMany(cascade = CascadeType.PERSIST, mappedBy = "owner")
>     Collection<Place> subplaces = new Vector<Place>();
>
>     @ManyToOne(cascade = CascadeType.PERSIST)
>     private Place owner;
>     .
>     .
>     .
> }
> When I use the default strategy (InheritanceType.SINGLE_TABLE) it works
> fine, but with InheritanceType.TABLE_PER_CLASS the following error raise:
>
> Exception in thread "main" java.lang.ExceptionInInitializerError
>     at gonjpa.Main.main(Main.java:44)
> Caused by: <0.9.7-incubating fatal user error>
> org.apache.openjpa.persistence.ArgumentException: "
> gonjpa.zones.Place.subplaces" declares a to-many relation strategy, but its
> elements are not direct, non-embedded relations to another mapped
> persistence-capable object.
>     at
> org.apache.openjpa.jdbc.meta.strats.RelationToManyInverseKeyFieldStrategy.map
> (RelationToManyInverseKeyFieldStrategy.java:116)
>     at
> org.apache.openjpa.jdbc.meta.strats.RelationCollectionInverseKeyFieldStrategy.map
> (RelationCollectionInverseKeyFieldStrategy.java:95)
>     at org.apache.openjpa.jdbc.meta.FieldMapping.setStrategy(
> FieldMapping.java:120)
>     at org.apache.openjpa.jdbc.meta.RuntimeStrategyInstaller.installStrategy
> (RuntimeStrategyInstaller.java:80)
>     at org.apache.openjpa.jdbc.meta.FieldMapping.resolveMapping(
> FieldMapping.java:438)
>     at org.apache.openjpa.jdbc.meta.FieldMapping.resolve(FieldMapping.java
> :403)
>     at org.apache.openjpa.jdbc.meta.ClassMapping.resolveMapping(
> ClassMapping.java:784)
>     at org.apache.openjpa.meta.ClassMetaData.resolve(ClassMetaData.java
> :1585)
>     at org.apache.openjpa.meta.MetaDataRepository.processBuffer(
> MetaDataRepository.java:659)
>     at org.apache.openjpa.meta.MetaDataRepository.resolveMapping(
> MetaDataRepository.java:620)
>     at org.apache.openjpa.meta.MetaDataRepository.resolve(
> MetaDataRepository.java:498)
>     at org.apache.openjpa.meta.MetaDataRepository.getMetaData(
> MetaDataRepository.java:288)
>     at org.apache.openjpa.meta.MetaDataRepository.resolveMeta(
> MetaDataRepository.java:524)
>     at org.apache.openjpa.meta.MetaDataRepository.resolve(
> MetaDataRepository.java:484)
>     at org.apache.openjpa.meta.MetaDataRepository.getMetaData(
> MetaDataRepository.java:288)
>     at org.apache.openjpa.jdbc.meta.MappingRepository.getMapping(
> MappingRepository.java:279)
>     at org.apache.openjpa.jdbc.meta.MappingTool.getMapping(MappingTool.java
> :670)
>     at org.apache.openjpa.jdbc.meta.MappingTool.buildSchema(MappingTool.java
> :742)
>     at org.apache.openjpa.jdbc.meta.MappingTool.run(MappingTool.java:640)
>     at org.apache.openjpa.jdbc.kernel.JDBCBrokerFactory.synchronizeMappings(
> JDBCBrokerFactory.java:164)
>     at org.apache.openjpa.jdbc.kernel.JDBCBrokerFactory.newBrokerImpl(
> JDBCBrokerFactory.java:130)
>     at org.apache.openjpa.kernel.AbstractBrokerFactory.newBroker(
> AbstractBrokerFactory.java:174)
>     at org.apache.openjpa.kernel.DelegatingBrokerFactory.newBroker(
> DelegatingBrokerFactory.java:142)
>     at
> org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(
> EntityManagerFactoryImpl.java:190)
>     at
> org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(
> EntityManagerFactoryImpl.java:143)
>     at
> org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(
> EntityManagerFactoryImpl.java:55)
>
>
> Am I missing something? I think that it isn't recognizing the field owner as
> a persistence capable entity.
> If I wasn't clear enough please let me know.
>
>
> Thanks in advance
>
>
> --
>                         Mariano Martín Heredia
>
> P.S: Congratulations to all the people involved in OJPA for the excelent
> product and the so complete documentation!
>


-- 
Patrick Linskey
202 669 5907

Mime
View raw message