users@glassfish.java.net

Mapping collection of wildcard generic type

From: <glassfish_at_javadesktop.org>
Date: Wed, 08 Oct 2008 12:52:00 PDT

Hello everyone,

I have tried to do something with my model and I am not sure whether this is right or wrong. Here comes my attempt :

Let's suppose I have 2 entities : Expense and Resource and the relationship between them is many-to-many :

[code]

@Entity
public class Expense {
        ..........................................................
        @ManyToMany
        private Collection<Resource> resources;
        ..........................................................

       //forget about the constructors and accessors
}

@Entity
public class Resource {
           // bla bla bla ... dumb simple
}

[/code]

The code above is working.

Now, I have tried to add wildcard to my resources collection and my code turns into :

[code]

@Entity
public class Expense {
        ..........................................................
        @ManyToMany
        private Collection< ? extends Resource > resources;
        ..........................................................

       //forget about the constructors and accessors
}

[/code]

When I am doing this I get the following deployment exception in Glassfish v2 Final Build ( I am deploying this as part of a EAR ) :

-------------------------------------------------------------------------------------------------------------------------------
Message ID
        
Exception occured in J2EEC Phase com.sun.enterprise.deployment.backend.IASDeploymentException
Complete Message
        
Exception [TOPLINK-28018] (Oracle TopLink Essentials - 2.0.1 (Build b04-fcs (04/11/2008))): oracle.toplink.essentials.exceptions.EntityManagerSetupException Exception Description: predeploy for PersistenceUnit [bmPersistenceContext] failed. Internal Exception: java.lang.ClassCastException: sun.reflect.generics.reflectiveObjects.WildcardTypeImpl cannot be cast to java.lang.Class at oracle.toplink.essentials.internal.ejb.cmp3.EntityManagerSetupImpl.predeploy(EntityManagerSetupImpl.java:643) at oracle.toplink.essentials.ejb.cmp3.EntityManagerFactoryProvider.createContainerEntityManagerFactory(EntityManagerFactoryProvider.java:244) at com.sun.jdo.spi.persistence.support.ejb.ejbc.PersistenceProcessor.loadPersistenceUnitBundle(PersistenceProcessor.java:512) at com.sun.jdo.spi.persistence.support.ejb.ejbc.PersistenceProcessor.createTablesInDB(PersistenceProcessor.java:353) at com.sun.jdo.spi.persistence.support.ejb.ejbc.PersistenceProcessor.processAppBundle(PersistenceProcessor.java:219) at com.sun.jdo.spi.persistence.support.ejb.ejbc.PersistenceProcessor.processApplication(PersistenceProcessor.java:146) at com.sun.jdo.spi.persistence.support.ejb.ejbc.DeploymentEventListenerImpl.processApplication(DeploymentEventListenerImpl.java:211) at com.sun.jdo.spi.persistence.support.ejb.ejbc.DeploymentEventListenerImpl.processEvent(DeploymentEventListenerImpl.java:172) at com.sun.jdo.spi.persistence.support.ejb.ejbc.DeploymentEventListenerImpl.notifyDeploymentEvent(DeploymentEventListenerImpl.java:122) at com.sun.enterprise.deployment.backend.DeploymentEventManager.notifyDeploymentEvent(DeploymentEventManager.java:79) at com.sun.enterprise.deployment.backend.AppDeployer.postDeploy(AppDeployer.java:392) at com.sun.enterprise.deployment.backend.AppDeployer.deploy(AppDeployer.java:251) at com.sun.enterprise.deployment.backend.AppDeployer.doRequestFinish(AppDeployer.java:148) at com.sun.enterprise.deployment.phasing.J2EECPhase.runPhase(J2EECPhase.java:191) at com.sun.enterprise.deployment.phasing.DeploymentPhase.executePhase(DeploymentPhase.java:108) at com.sun.enterprise.deployment.phasing.PEDeploymentService.executePhases(PEDeploymentService.java:919) at com.sun.enterprise.deployment.phasing.PEDeploymentService.deploy(PEDeploymentService.java:279) at com.sun.enterprise.deployment.phasing.PEDeploymentService.deploy(PEDeploymentService.java:788) at com.sun.enterprise.management.deploy.DeployThread.deploy(DeployThread.java:187) at com.sun.enterprise.management.deploy.DeployThread.run(DeployThread.java:223)
-------------------------------------------------------------------------------------------------------------------------------

I think what I have tried to do is a reasonable thing and I expected it should have worked somehow similar with the JPA inheritance types. It is also true that I do not have any instance of Expense type nor any other usage of it. It "just sits there" at the moment and there's no chance for type erasure to happen and possibly detect the type of a possible entity.

I understand there must be a an existing type there but in case it is not, the base type should be used along with one of the inheritance types to map the collection.

Anyway, I am still not sure whether what I have tried to achieve is correct or not, ORM wise, however this is valid OO design.

Questions :

1. Is it correct in terms of O-R mapping ?
2. If this is correct, has this issue been addressed ?
3. If this has been addressed, is it a bug or am I missing something ?

Thank you,

Kind Regards,

Razvan
[Message sent by forum member 'razvand' (razvand)]

http://forums.java.net/jive/thread.jspa?messageID=304080