openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Krzysztof <yaz...@gmail.com>
Subject Key and Value limitations in a Map<Key,Value>
Date Wed, 05 Aug 2009 16:31:53 GMT

Hello,
Seems I am completely knotted in a convoluted class graph without any hint
from documentation, spec or forum archive. 

Could somebody enlighten me if it is possible to:

A. Have a Key in a persistent Map<Key,Value> such as 
 1. the Key has a composite ID composed of classes which have composite IDs
themselves? 
 and
 2. They Key is an abstract class that is also used in a Value as a parent
in ManyToOne relationship being the part of the Values identity (actual
objects - parent and Value being rather different entities)

Hope this example clarifies this rather complicated scenario: 

//abstract class of which children are Values in a map
@Entity
@IdClass(AbstractTS.TSId.class) //TSId covers SomeOtherClass identity too
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public abstract class AbstractTS
{
 @id SomeOtherClass parent;
 @id int local_id;
 @OneToMany
 private Map<ModelId, DerivedTS> derivedMap; // DerivedTS inherits from
AbstractTS - seems to impossible to be mapped properly.

}

// abstract class that has common identity and some additional fields, it is
a Key in a map
@Inheritance(strategy = InheritanceType.JOINED)
@MappedSuperclass
@IdClass(ModelId.ModelImplId.class)
public abstract class AbstractModel { 
 @id  AbstractTS parent;
 @id  int x;
 @id double y;

 @Basic
 @Lob
 double[] some_common_data;
}

// Identity domain class, that is in fact stripped down version of an
abstractModel, both reuse same ID class,  used to retrieve unknown models.

@IdClass(ModelId.ModelImplId.class)
@Embeddable
public class ModelId  {
    
    @ManyToOne
    public AbstractTS parentTS; //could be either DerivedTS or RawTS.
    @Id
    @Basic
    public double some_value;
    @Id
    public int modelType;

    @Basic
    int some_derived_value;

}

@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
//identity derived from AbstractTS
public class RawTS extends AbstractTS
{
 @Basic 
 int some_values;
}

@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
@IdClass(DerivedTS.DerivedTSId.class) // inherits from TSId with additional
Identities for parentTS and parentModel
public class  DerivedTS extends AbstractTS {
	@ManyToOne
	//@PrimaryKeyJoinColumns(..) // possibly to provide direct mappings to
either RawTS or DerivedTS identity fields
        @Id
	private AbstractTS parentTS;
      
        @Id
        @ManyToOne
        //@PrimaryKeyJoinColumns( {... }) //possibly to provide direct
mappings to any model derived from AbstractModel
       private AbstractModel parentModel = null;

}



To create any working mapping for

Map<ModelId, DerivedTS> seems like an impossible mission, I would appreciate
any hints if it is doable at all.

I tried various combinations of @ManyToOne combined with @PrimaryKeys,
@MapPrimaryKeys, @ElementCollection etc.
Persistence.xml lists all the classes, using openjpa 2.0.0 snapshot.

The last error I got is during enhancement:
   [java] Exception in thread "main" <openjpa-2.0.0-SNAPSHOT-r422266:798026
fatal user error> org.apache.openjpa.util.MetaDataException: Errors
encountered while resolving metadata.  See nested exceptions for details.
     [java] 	at
org.apache.openjpa.meta.MetaDataRepository.resolve(MetaDataRepository.java:578)
     [java] 	at
org.apache.openjpa.meta.MetaDataRepository.getMetaData(MetaDataRepository.java:323)
     [java] 	at
org.apache.openjpa.meta.MetaDataRepository.resolveMeta(MetaDataRepository.java:625)
     [java] 	at
org.apache.openjpa.meta.MetaDataRepository.resolve(MetaDataRepository.java:556)
     [java] 	at
org.apache.openjpa.meta.MetaDataRepository.getMetaData(MetaDataRepository.java:323)
     [java] 	at
org.apache.openjpa.enhance.PCEnhancer.<init>(PCEnhancer.java:251)
     [java] 	at
org.apache.openjpa.enhance.PCEnhancer.run(PCEnhancer.java:4593)
     [java] 	at
org.apache.openjpa.enhance.PCEnhancer.run(PCEnhancer.java:4540)
     [java] 	at
org.apache.openjpa.enhance.PCEnhancer$1.run(PCEnhancer.java:4510)
     [java] 	at
org.apache.openjpa.lib.conf.Configurations.launchRunnable(Configurations.java:726)
     [java] 	at
org.apache.openjpa.lib.conf.Configurations.runAgainstAllAnchors(Configurations.java:711)
     [java] 	at
org.apache.openjpa.enhance.PCEnhancer.run(PCEnhancer.java:4505)
     [java] 	at
org.apache.openjpa.enhance.PCEnhancer.main(PCEnhancer.java:4496)
     [java] Caused by: <openjpa-2.0.0-SNAPSHOT-r422266:798026 fatal user
error> org.apache.openjpa.util.MetaDataException: Field
"DerivedTS.parentModel" cannot be a primary key.  It is of an unsupported
type.
     [java] 	at
org.apache.openjpa.meta.ClassMetaData.validateAppIdClassPKs(ClassMetaData.java:2105)
     [java] 	at
org.apache.openjpa.meta.ClassMetaData.validateAppIdClass(ClassMetaData.java:1989)
     [java] 	at
org.apache.openjpa.meta.ClassMetaData.validateIdentity(ClassMetaData.java:1925)
     [java] 	at
org.apache.openjpa.meta.ClassMetaData.validateMeta(ClassMetaData.java:1842)
     [java] 	at
org.apache.openjpa.meta.ClassMetaData.resolve(ClassMetaData.java:1704)
     [java] 	at
org.apache.openjpa.meta.MetaDataRepository.processBuffer(MetaDataRepository.java:733)
     [java] 	at
org.apache.openjpa.meta.MetaDataRepository.resolveMeta(MetaDataRepository.java:631)
     [java] 	at
org.apache.openjpa.meta.MetaDataRepository.resolve(MetaDataRepository.java:556)
     [java] 	... 12 more
     [java] NestedThrowables: 


It fails in validateAppIdClassPKs, but it is hard to guess with what type:
...
2101		  case JavaTypes.PC_UNTYPED:
2102                 case JavaTypes.COLLECTION:
2103                 case JavaTypes.MAP:
2104                 case JavaTypes.OID: // we're validating embedded fields
2105                     throw new MetaDataException(_loc.get("bad-pk-type",
2106                         fmds[i]));
....

Does it mean Composite IDs are banned in Map's Key completely?


Best regards,
Krzysztof
-- 
View this message in context: http://n2.nabble.com/Key-and-Value-limitations-in-a-Map%3CKey%2CValue%3E-tp3393262p3393262.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Mime
View raw message