Persistence Unit / Entity class question

Hi guys.
I'm trying to get a list of all entity classes in an EJB project. What would be the easiest way of doing this? I think there should be a way to obtain the persistence unit and get a list of entity classes from that, but I can't find a way to do this. The only other way that I can think of is to manually go and read the persistence.xml file, but I'd like to avoid that. Any advice will be much appreciated. Thanks!
I've discovered the PersistenceUnitInfo interface, which looks like it might be of some use. However, I can't find a way to inject it into a bean. Any ideas? Thanks!

Are your Entities in a jar in the web-inf/lib of your web app? Do you have a single persistence unit? I looks like either a classloader or wrong persistence unit problem.
Can you post the full stack?
--Shaun                                                                                                                                                                                                                                                                                                                                                                                                                                                   

Similar Messages

  • Can i pass the persistence unit to the Ejb before it inject the entity mana

    Hey,
    The user in my system can create his personal schema, so i need to work with multiple schemas.
    As i understand i need to create at run time persistence unit for each schema.
    The problem is that my DAO i inject the entity manager in the following way:
    @PersistenceContext(persistenceUnit="bla-bla")
    public void setEntityManager(EntityManager em) {
    this.em = em;
    }i need to write the persistence unit name hard coded.
    How can i solve this?
    Thank you

    There's no way to get this kind of dynamic association to a persistence unit for container-managed
    persistence contexts. You'll need to explicitly create an EntityManager using the
    EntityManagerFactory API, where you specify the name of the persistence unit at runtime. Even in
    that case, the persistence unit must already be defined.
    --ken                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Error checking for persistence unit annotations in the main class

    Hi
    When I tried running the examples from the SUN JMS tutorials, I landed in a problem. I did the following changes...
    1. I created a new project in eclipse
    2. created the java class 'Producer.java' in a package..(the one in java tutorial is not in a package)
    3. copied the build.xml and made the the respective changes.
    I successfully created the jar file, but when I tried to run the the application
    appclient -client JMSProducer.jar eg.jms.P2PProducer.Producer queue 3it throws the following exception:
    Nov 29, 2006 3:40:33 PM com.sun.enterprise.deployment.annotation.impl.ModuleScan
    ner getElements
    WARNING: Cannot load ${main.class} reason : ${main.class}
    Nov 29, 2006 3:40:33 PM com.sun.enterprise.appclient.MainWithModuleSupport <init
    >
    WARNING: ACC003: Application threw an exception.
    java.lang.RuntimeException: Error checking for persistence unit annotations in t
    he main class
            at com.sun.enterprise.appclient.StandAloneAppClientInfo.classContainsAnn
    otation(StandAloneAppClientInfo.java:88)
            at com.sun.enterprise.appclient.AppClientInfo.mainClassContainsPURefcAnn
    otations(AppClientInfo.java:342)
            at com.sun.enterprise.appclient.AppClientInfo.appClientDependsOnPersiste
    nceUnit(AppClientInfo.java:311)
            at com.sun.enterprise.appclient.AppClientInfo.completeInit(AppClientInfo
    .java:164)
            at com.sun.enterprise.appclient.AppClientInfoFactory.buildAppClientInfo(
    AppClientInfoFactory.java:136)
            at com.sun.enterprise.appclient.MainWithModuleSupport.<init>(MainWithMod
    uleSupport.java:287)
            at com.sun.enterprise.appclient.Main.main(Main.java:180)
    Caused by: java.lang.NullPointerException
            at java.util.zip.ZipFile.getInputStream(ZipFile.java:286)
            at java.util.jar.JarFile.getInputStream(JarFile.java:387)
            at com.sun.enterprise.deployment.util.AnnotationDetector.containsAnnotat
    ion(AnnotationDetector.java:139)I have spent so much time identifying the problem... can anyone point the error please?

    I'm having the same problem, albeit 18 months later. I am working with a tutorial from apress, which seems very high on Glassfish as a AppServer environment for learning EJB 3.0. I have the same error when I try to run the client application in the Sun Platform 9.0 Application Server's AppClient Module container , "... Error checking for persistence unit annotations in the main class..." and I think it has something to do with the fact that the AppClient is expecting "something" in the MANIFEST.MF file that actually isn't there... ( sigh ). " so close, and yet so far away.... "
    --- andyj748

  • Newbie question on Java Persistence API - Entity Beans

    Hi All,
    I am basically new to Entities and the Java Persistence API. My question is, when using a container managed EntityManager, do I have to manually tidy-up any resources? Say for example, do I have to explicitly close the database connection (if ever I have that ability)? Invoke close() on EntityManager?
    - Pat

    You don't have to. That's what they mean by container managed. The container does it for you.
    In fact you will get an IllegalStateException if you call close on a container-managed EntityManager.

  • Managing persistence units across different EJB modules

    Hi,
    I'm testing some things and I have the following situation :
    1 EJB module (.JAR) with basic EJBs and entities
    1 EJB module (.JAR) with EJBs and entities that extend some base entities
    Now, I've placed a persistence.xml in each both defining a persistence unit with the same name (I want both EJB modules, or more specifically the injected EntityManagers therein to know about both the basic as well as the extended entities).
    My question is, what is the correct way to set up a project so you can have some core functionality EJBs and entities, and some optional extension EJBs and entities in such a way that a single persistence unit is used for all entities.
    I hope anyone can help me out here. Thanks.

    Persistence unit will not share references to entity in terms of the inheritance you want to achieve.
    I think the only way you can do that is you the @MappedSuperClass on a class. THis is because the class so annotated is not entered in any of the persistence unit and thus can be shared. I have used it and it works.
    Regards,
    Michael

  • Multiple persistence units and OneToMany associations

    Hi,
    I have an EAR with two persistence units and corresponding entities. Each is contained within a separate library jar file. Some of the entities in one of the jars refer to entities in the other jar. If I refer to just a single entity (i.e., a OneToOne association), everything builds and deploys with no problems, but if I use a collection (OneToMany association), I get errors when trying to deploy the project.
    I've been playing around with this for a while and have seen different errors such as the following:
    [exec] CLI171 Command deploy failed : Deploying application in domain failed; Exception [TOPLINK-28018] (Oracle TopLink Essentials - 2.0.1 (Build b04-fcs (04/11/2008))): oracle.toplink.essentials.exceptions.EntityManagerSetupException
    [exec] Exception Description: predeploy for PersistenceUnit [GrammarUserData] failed.
    [exec] Internal Exception: Exception [TOPLINK-7155] (Oracle TopLink Essentials - 2.0.1 (Build b04-fcs (04/11/2008))): oracle.toplink.essentials.exceptions.ValidationException
    [exec] Exception Description: The type [interface java.util.List] for the attribute [sentencePatterns] on the entity class [class com.leadingstep.grammar.configuration.CommonElementConfiguration] is not a valid type for a serialized mapping. The attribute type must implement the Serializable interface.
    I also had the collection defined as a Set and it complained about that as well. I have many other OneToMany associations used between entities within the same persistence unit that use the List interface with no problems, and so that's why I'm wondering if the problem actually comes from the fact that the entities in the failed case belong to different persistence units?
    At another point, the error message I was getting was:
    [#|2009-12-22T20:05:02.427-0500|SEVERE|sun-appserver9.1|javax.enterprise.system.tools.deployment|_ThreadID=15;_ThreadName=Thread-32;_RequestID=67ca0eee-64d9-41dc-8093-eec811cb32b6;|Exception occured in J2EEC Phase
    com.sun.enterprise.deployment.backend.IASDeploymentException: 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 [GrammarUserData] failed.
    Internal Exception: Exception [TOPLINK-7250] (Oracle TopLink Essentials - 2.0.1 (Build b04-fcs (04/11/2008))): oracle.toplink.essentials.exceptions.ValidationException
    Exception Description: [class com.leadingstep.grammar.configuration.CommonConstructorConfiguration] uses a non-entity [class com.leadingstep.grammar.db.sentences.SentenceGroup] as target entity in the relationship attribute [private java.util.List com.leadingstep.grammar.configuration.CommonConstructorConfiguration.sentenceGroups].
    The target entity it refers to here definitely has the @Entity annotation and again, is associated with other entities within the same persistence unit with no problems.
    Am I right in thinking the problem comes from the association of entities between the different persistence units? Is there something special I have to do to make this work?
    BTW, both persistence units use the <exclude-unlisted-classes> and specifically list every entity that should be included.
    Thanks for any help!
    Renee

    One other thought on this. I'm using Glassfish with Toplink and have it create the tables using:
                   <property name="toplink.ddl-generation" value="create-tables" />
    Could it be something related to the table creation in this case that's causing the problem?
    Renee

  • Weblogic 10.3.0 not picking up persistence unit

    Hello,
    I am facing a problem where Weblogic does not seem to pickup the persistence unit:
    [wldeploy] Target state: deploy failed on Server examplesServer
    [wldeploy] java.lang.IllegalArgumentException: No persistence unit named 'dao' is available in scope ejb-app. Available persistence units: []OS: Windows XP (Development Environemnt)
    WebLogic Server Version: 10.3.0.0
    Though I'm working via Eclipse Helios, I am using Weblogic generated (and later modified) Ant scripts to compile, build and deploy to my local Weblogic install, in a 'split development' setup.
    Following is the file strutcture:
    source
    +---build.xml (Ant script)
    +---APP-INF
    |    +---lib
    |         +--- * (shared libraries)
    |
    +---META-INF
    |    +---application.xml
    |    +---weblogic-application.xml
    |
    +---web-app
    |    +---WEB-INF
    |         +---src
    |         +---lib
    |
    +---ejb-app
         +---com.example.ejb.data (Contains Entity annotations)
          |    +---Pojo1.java
          |    +---Pojo2.java
          |
          +---com.example.ejb.ctrl (Contains business logic and services)
          |    +---MyService.java
          |
          +---META-INF
               +---ejb-jar.xml
                +---weblogic-ejb-jar.xml
                +---persistence.xml     Here is my persistence.xml:
    <?xml version="1.0"?>
    <persistence xmlns="http://java.sun.com/xml/ns/persistence"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
        http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
         version="1.0">
         <persistence-unit name="dao" transaction-type="RESOURCE_LOCAL">
              <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
              <jta-data-source>OraDS</jta-data-source>
              <non-jta-data-source>OraDS</non-jta-data-source>
              <class>com.example.ejb.data.Pojo1</class>
              <class>com.example.ejb.data.Pojo2</class>
              <properties>
                   <property name="eclipselink.target-server" value="WebLogic_10" />
                   <property name="eclipselink.logging.level" value="FINEST" />
              </properties>
         </persistence-unit>
    </persistence>            I am attempting to inject the persistence unit via annotation in MyService.java (a @Stateless session bean):
    @PersistenceContext(unitName = "dao")
    private EntityManager entityManager;     I had done the same with 10.3.0's default Kodo provider and was getting the same issue.
    I've moved the persistence.xml to source/APP-INF, source/APP-INF/lib, source/META-INF and run deploys, it still gives me the error.
    The whole EAR is built with wlcompile and appc as per Split Directory development flow.
    For some reason, Weblogic does not seem to pick up the "dao" persistence unit into its JNDI tree, application wide or 'ejb-app' module scoped.
    Any direction on what next should I be looking at would be helpful.
    Edited by: Vyoma on May 25, 2011 10:15 PM
    Fixed code formatting.

    Pierluigi Vernetto, thanks for that link. Though it was for a web module consumption of the persistence package, I was able to adapt it for use by my ejb module.
    Here is my solution, under split-directory development workflow.
    Create the persistence module, place the persistence.xml in that module's META-INF.
    Create an Ant task in the build.xml to 'wlcompile' and JAR it to the EAR direcotries APP-INF/lib directory.
    Exclude the persistence module from the rest of the 'wlcompile' and 'appc' tasks.
    I was then able to inject it with annotation in my EJB module.
    dvohra16, thanks for that pointer. Now that I've been able to solve, the pressure is off (and shifted to other things). But I will surely check your option out. If I can get that working, it will be much easier than tinkering around with the build.xml and would be the normal flow of split-directory development workflow.
    As of now, I will say this thread as 'solved', but if I get it working the way you mention (on my sandbox project), I will surely come back and update this thread.
    Edited by: Vyoma on May 27, 2011 11:21 AM

  • Weblogic 12c not picking up persistence unit in WAR

    I'm trying to get an example CRUD application to run on WebLogic 12c (for the app see: http://henk53.wordpress.com/2012/04/15/jsf2-primefaces3-ejb3-jpa2-integration-project/)
    So far the applications runs on JBoss AS 7.1, GlassFish 3.1.2 and TomEE beta 2. In all those application servers persistence.xml is picked-up, and processed so I'm at a loss what's wrong with WebLogic. I'm using Eclipse 3.7.2 and the Oracle WebLogic 12C WTP server adapter for the deployment.
    I'm getting the following exception:
    java.lang.IllegalArgumentException: No persistence unit named 'entityManager' is available in scope jsf_ejb_jpa. Available persistence units: []
         at weblogic.persistence.ModulePersistenceUnitRegistry.getPersistenceUnit(ModulePersistenceUnitRegistry.java:130)
         at weblogic.persistence.BasePersistenceContextProxyImpl.<init>(BasePersistenceContextProxyImpl.java:40)
         at weblogic.persistence.TransactionalEntityManagerProxyImpl.<init>(TransactionalEntityManagerProxyImpl.java:31)
         at weblogic.persistence.EntityManagerInvocationHandlerFactory.createTransactionalEntityManagerInvocationHandler(EntityManagerInvocationHandlerFactory.java:20)
         at weblogic.persistence.PersistenceManagerObjectFactory.createPersistenceContextProxy(PersistenceManagerObjectFactory.java:66)
         at weblogic.persistence.PersistenceManagerObjectFactory.getObjectInstance(PersistenceManagerObjectFactory.java:31)
         at javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:304)
         at weblogic.jndi.internal.WLEventContextImpl.lookup(WLEventContextImpl.java:251)
         at weblogic.jndi.internal.WLContextImpl.lookup(WLContextImpl.java:406)
         at weblogic.j2eeclient.java.ClientReadOnlyContextWrapper.lookup(ClientReadOnlyContextWrapper.java:35)
         at weblogic.jndi.internal.AbstractURLContext.lookup(AbstractURLContext.java:130)
         at javax.naming.InitialContext.lookup(InitialContext.java:392)
         at javax.naming.InitialContext.doLookup(InitialContext.java:265)
         at com.oracle.pitchfork.inject.Jsr250Metadata.jndiLookup(Jsr250Metadata.java:307)
         at com.oracle.pitchfork.inject.Jsr250Metadata.resolveByName(Jsr250Metadata.java:303)
         at com.oracle.pitchfork.inject.Jsr250Metadata.resolve(Jsr250Metadata.java:266)
         at com.oracle.pitchfork.inject.Jsr250Metadata.applyInjections(Jsr250Metadata.java:228)
         at com.oracle.pitchfork.inject.Jsr250Metadata.inject(Jsr250Metadata.java:219)
         at com.oracle.pitchfork.spi.BaseComponentBrokerImpl.getBean(BaseComponentBrokerImpl.java:63)
         at com.oracle.pitchfork.spi.EjbComponentCreatorBrokerImpl.getBean(EjbComponentCreatorBrokerImpl.java:33)
         at weblogic.ejb.container.injection.EjbComponentCreatorImpl.getBean(EjbComponentCreatorImpl.java:76)
         at weblogic.ejb.container.manager.BaseEJBManager.createNewBeanInstance(BaseEJBManager.java:209)
         at weblogic.ejb.container.manager.BaseEJBManager.allocateBean(BaseEJBManager.java:235)
         at weblogic.ejb.container.manager.StatelessManager.createBean(StatelessManager.java:293)
         at weblogic.ejb.container.pool.StatelessSessionPool.createBean(StatelessSessionPool.java:185)
         at weblogic.ejb.container.pool.StatelessSessionPool.getBean(StatelessSessionPool.java:114)
         at weblogic.ejb.container.manager.StatelessManager.preInvoke(StatelessManager.java:174)
         at weblogic.ejb.container.internal.BaseLocalObject.getBeanInstance(BaseLocalObject.java:146)
         at weblogic.ejb.container.internal.BaseLocalObject.preInvoke(BaseLocalObject.java:103)
         at weblogic.ejb.container.internal.BaseLocalObject.__WL_preInvoke(BaseLocalObject.java:67)
         at weblogic.ejb.container.internal.SessionLocalMethodInvoker.invoke(SessionLocalMethodInvoker.java:20)
         at com.example.dao.jpa.JpaUserDAO_wrkew_UserDAOImpl.add(Unknown Source)
         at com.example.backing.IndexBacking.addUser(IndexBacking.java:38)
    Notice that "entityManager" is the name of the instance variable in which injection is being performed:
    @PersistenceContext(name="example")
    private EntityManager entityManager;
    If I rename this variable to "em: as follows:
    @PersistenceContext(name="example")
    private EntityManager em;
    Then, lo and behold, the exception changes into:
    java.lang.IllegalArgumentException: No persistence unit named 'em' is available in scope jsf_ejb_jpa. Available persistence units: []
    As the example uses a data-source defined in web.xml, which is only marginally supported in most application servers, I tried to define a WebLogic specific application scoped data-source instead and let the persistence unit use that. I couldn't find a way to do this in a .war (is this even possible?), so I created an .ear archive instead. When deploying the EAR, the data-source is clearly being created, but I'm getting the same exception again.
    I finally created an EJB module with a persistence.xml and a simple Singleton that's injected with the entityManager, and added that to the EAR. This works for the EJB module, but in the web module injection of the other entity manager still fails.
    Any idea what might be the problem?

    After some more fiddling, I discovered it's not WebLogic itself that's at fault here, but most likely Oracle's WTP adapter. Apparently it doesn't include persistence.xml in the archive that gets deployed. When I export the project as an .ear archive and copy this to WebLogic's autodeploy directly, things do work.
    I tried to find out what the main difference was between the deployments, but I could not find where the Oracle WTP adapter creates the deployment. I tried to test where a resource inside the EAR resides on the filesystem via the following code inside a backing bean:
    URL url = Thread.currentThread().getContextClassLoader().getResource("com/example/backing");
    It looks like there isn't a real .war or .ear being created and deployed, but there's a link back to the workspace, as the URL resolves to:
    file:/Users/henk/eclipse37ee/workspace/jsf_ejb_jpa/build/classes/com/example/backing/
    If I execute the same code for the ear in the autodeploy folder, the URL resolves to some jar inside:
    /Users/henk/eclipse37ee/wls1211_dev/mydomain/servers/myserver/tmp/_WL_user/_appsdir_jsf_ejb_jpa_ear_ear/2jzks6/war/WEB-INF/lib/
    In case of the WTP 'deployment' linking back to the Eclipse workspace, META-INF/persistence.xml is actually there too, but for some reason Weblogic can't find it there?
    Edited by: Henk on Apr 29, 2012 2:57 PM

  • Duplicate persistence units in JPA weblogic

    Hello, I'm cross-posting thsi question from weblogic forum as a suggestion from james.bayer.
    I am using weblogic 10.3.
    I am trying to deploy a spring web application with severaljars, that contain jpa entities with a persistence.xml. The persistence unit name in all persistence.xml are equal. That is for spring no problem, because i wrote a PersistenceUnitManager, that merges all persistence units into one.
    So far so good. But weblogic cant't deploy the war, because while validation of the deployment, wls throws an exception, that there are two persistence unit with the same name.
    Does anybody has an idea how to deploy this war?
    Can i switch off the validation of the persistence.xml?
    The full stack trace is:
    weblogic.application.ModuleException: Failed to load webapp: 'sfw-poc-condicao-pagamento-web.war'
         at weblogic.servlet.internal.WebAppModule.prepare(WebAppModule.java:404)
         at weblogic.application.internal.flow.ScopedModuleDriver.prepare(ScopedModuleDriver.java:180)
         at weblogic.application.internal.flow.ModuleListenerInvoker.prepare(ModuleListenerInvoker.java:199)
         at weblogic.application.internal.flow.DeploymentCallbackFlow$1.next(DeploymentCallbackFlow.java:508)
         at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:41)
         at weblogic.application.internal.flow.DeploymentCallbackFlow.prepare(DeploymentCallbackFlow.java:149)
         at weblogic.application.internal.flow.DeploymentCallbackFlow.prepare(DeploymentCallbackFlow.java:47)
         at weblogic.application.internal.BaseDeployment$1.next(BaseDeployment.java:1223)
         at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:41)
         at weblogic.application.internal.BaseDeployment.prepare(BaseDeployment.java:367)
         at weblogic.application.internal.SingleModuleDeployment.prepare(SingleModuleDeployment.java:43)
         at weblogic.application.internal.DeploymentStateChecker.prepare(DeploymentStateChecker.java:154)
         at weblogic.deploy.internal.targetserver.AppContainerInvoker.prepare(AppContainerInvoker.java:60)
         at weblogic.deploy.internal.targetserver.AppDeployment.prepare(AppDeployment.java:141)
         at weblogic.management.deploy.internal.DeploymentAdapter$1.doPrepare(DeploymentAdapter.java:40)
         at weblogic.management.deploy.internal.DeploymentAdapter.prepare(DeploymentAdapter.java:191)
         at weblogic.management.deploy.internal.AppTransition$1.transitionApp(AppTransition.java:22)
         at weblogic.management.deploy.internal.ConfiguredDeployments.transitionApps(ConfiguredDeployments.java:240)
         at weblogic.management.deploy.internal.ConfiguredDeployments.prepare(ConfiguredDeployments.java:166)
         at weblogic.management.deploy.internal.ConfiguredDeployments.deploy(ConfiguredDeployments.java:122)
         at weblogic.management.deploy.internal.DeploymentServerService.resume(DeploymentServerService.java:181)
         at weblogic.management.deploy.internal.DeploymentServerService.start(DeploymentServerService.java:97)
         at weblogic.t3.srvr.SubsystemRequest.run(SubsystemRequest.java:64)
         at weblogic.work.ExecuteThread.execute(ExecuteThread.java:201)
         at weblogic.work.ExecuteThread.run(ExecuteThread.java:173)
    Caused By: weblogic.deployment.EnvironmentException: duplicate persistence units with name sfw-persistence-unit in scope sfw-poc-condicao-pagamento-web.war. First PU location: file:/C:/java/servers/Oracle/Middleware/user_projects/domains/base_domain/servers/softway/tmp/_WL_user/sfw-poc-condicao-pagamento-web/rrg25b/war/WEB-INF/lib/sfw-class-loader-0.0.1-SNAPSHOT.jar. Second PU location: file:/C:/java/servers/Oracle/Middleware/user_projects/domains/base_domain/servers/softway/tmp/_WL_user/sfw-poc-condicao-pagamento-web/rrg25b/war/WEB-INF/lib/sfw-custom-jar-0.0.1-20100622.030351-65.jar
         at weblogic.deployment.AbstractPersistenceUnitRegistry.assertNoDuplicate(AbstractPersistenceUnitRegistry.java:313)
         at weblogic.deployment.AbstractPersistenceUnitRegistry.processDescriptor(AbstractPersistenceUnitRegistry.java:291)
         at weblogic.deployment.AbstractPersistenceUnitRegistry.loadPersistenceDescriptor(AbstractPersistenceUnitRegistry.java:192)
         at weblogic.deployment.AbstractPersistenceUnitRegistry.loadPersistenceDescriptors(AbstractPersistenceUnitRegistry.java:101)
         at weblogic.deployment.ModulePersistenceUnitRegistry.<init>(ModulePersistenceUnitRegistry.java:58)
         at weblogic.servlet.internal.WebAppModule.setupPersistenceUnitRegistry(WebAppModule.java:1812)
         at weblogic.servlet.internal.WebAppModule.getWebClassLoader(WebAppModule.java:1604)
         at weblogic.servlet.internal.WebAppServletContext.initClassLoader(WebAppServletContext.java:2969)
         at weblogic.servlet.internal.WebAppServletContext.<init>(WebAppServletContext.java:438)
         at weblogic.servlet.internal.WebAppServletContext.<init>(WebAppServletContext.java:487)
         at weblogic.servlet.internal.HttpServer.loadWebApp(HttpServer.java:418)
         at weblogic.servlet.internal.WebAppModule.registerWebApp(WebAppModule.java:976)
         at weblogic.servlet.internal.WebAppModule.prepare(WebAppModule.java:381)
         at weblogic.application.internal.flow.ScopedModuleDriver.prepare(ScopedModuleDriver.java:180)
         at weblogic.application.internal.flow.ModuleListenerInvoker.prepare(ModuleListenerInvoker.java:199)
         at weblogic.application.internal.flow.DeploymentCallbackFlow$1.next(DeploymentCallbackFlow.java:508)
         at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:41)
         at weblogic.application.internal.flow.DeploymentCallbackFlow.prepare(DeploymentCallbackFlow.java:149)
         at weblogic.application.internal.flow.DeploymentCallbackFlow.prepare(DeploymentCallbackFlow.java:47)
         at weblogic.application.internal.BaseDeployment$1.next(BaseDeployment.java:1223)
         at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:41)
         at weblogic.application.internal.BaseDeployment.prepare(BaseDeployment.java:367)
         at weblogic.application.internal.SingleModuleDeployment.prepare(SingleModuleDeployment.java:43)
         at weblogic.application.internal.DeploymentStateChecker.prepare(DeploymentStateChecker.java:154)
         at weblogic.deploy.internal.targetserver.AppContainerInvoker.prepare(AppContainerInvoker.java:60)
         at weblogic.deploy.internal.targetserver.AppDeployment.prepare(AppDeployment.java:141)
         at weblogic.management.deploy.internal.DeploymentAdapter$1.doPrepare(DeploymentAdapter.java:40)
         at weblogic.management.deploy.internal.DeploymentAdapter.prepare(DeploymentAdapter.java:191)
         at weblogic.management.deploy.internal.AppTransition$1.transitionApp(AppTransition.java:22)
         at weblogic.management.deploy.internal.ConfiguredDeployments.transitionApps(ConfiguredDeployments.java:240)
         at weblogic.management.deploy.internal.ConfiguredDeployments.prepare(ConfiguredDeployments.java:166)
         at weblogic.management.deploy.internal.ConfiguredDeployments.deploy(ConfiguredDeployments.java:122)
         at weblogic.management.deploy.internal.DeploymentServerService.resume(DeploymentServerService.java:181)
         at weblogic.management.deploy.internal.DeploymentServerService.start(DeploymentServerService.java:97)
         at weblogic.t3.srvr.SubsystemRequest.run(SubsystemRequest.java:64)
         at weblogic.work.ExecuteThread.execute(ExecuteThread.java:201)
         at weblogic.work.ExecuteThread.run(ExecuteThread.java:173)
    Thanks a lot

    They need to have different names.
    James : http://www.eclipselink.org

  • Persistence Units: Transaction Type

    Hi,
    I'm just getting into Java EE 5 and EJB3. I've found many examples of persistence.xml files with the persistence-units' transaction-types set to either JTA or LOCAL_RESOURCE. What I haven't been able to find is any discussion on when one type should be used over the other.
    I've been playing a little in NetBeans 5.5 and created a persistence.xml for an entity class library. The design view of the xml file doesn't have any options to switch from one to the other (that I can see anyway). Mine is set to use RESOURCE_LOCAL. I know I could manually edit the file to use JTA, but should I? Why would I? Why does NB only allow for RESOURCE_LOCAL? I don't know how relevant it is, but the provider is toplink essentials.
    If anyone can point me to a good resource that discusses these issues, I would be grateful.
    Thanks in advance,
    Shelli

    You apparently have configured it as a container managed entity manager. It roughly means that the container is injecting the entity manager in the environment and controlling the transactions itself, rather than that you are controlling the transactions yourself in the code.
    Either change it to JTA to get the container to do the work, or if you want to keep it RESOURCE_LOCAL somehow, then stop using container managed injection and control the transactions yourself.
    This has not much to do with JDBC however. In the future better use the [EJB forum|http://forums.sun.com/forum.jspa?forumID=13].

  • Toplink JPA properties in persistence unit are ignored

    I'm trying to make some EJB3 stateless session bean webservices, using the toplink essentials (build b41 beta 2) shipped with OC4J stand-alone 10.1.3.3.0.
    Basically I have a 'model' project with my EJB3 entity beans, and a persistence.xml. Then I have a webservice project, that has the model project as a dependency. Both projects are in the same application in JDeveloper. I use a deployment profile to deploy to my seperate OC4J stand-alone instance.
    My service runs and deploys fine. The persistence unit is read, and the correct datasource is selected and logged in on. However I notice two things:
    - the container complains during deployment, telling me property toplink.server.platform.class.name is deprecated and I should use toplink.target-server. However, I've set the property toplink.target-server as a property in my persistence.xml file...
    - I don't see any Toplink logging, although I've set the property toplink.logging.level to FINE in the persistence.xml.
    This leads me to believe that the properties are somehow ignored. Has anyone experienced this as well? Any hints/tips/suggestions on how to fix this?
    Cheers,
    Bas
    My persistence.xml:
    <?xml version="1.0" encoding="windows-1252" ?>
    <persistence xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                 xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
                 version="1.0" xmlns="http://java.sun.com/xml/ns/persistence">
      <persistence-unit name="VervoerPublicatiesPU" transaction-type="JTA">
        <provider>oracle.toplink.essentials.PersistenceProvider</provider>
        <jta-data-source>jdbc/SQLPUBDS</jta-data-source>
        <class>a.b.c.A</class>      
        <class>a.b.c.B</class>
        <properties>
            <property name="toplink.logging.level" value="FINE"/>
            <property name="oracle.toplink.essentials.config.CacheType" value="SoftWeak"/>
            <property name="toplink.target-database" value="SQLServer"/>
            <property name="toplink.target-server" value="OC4J_10_1_3"/>
        </properties>
      </persistence-unit>
    </persistence>

    I debugged this problem a few weeks ago. There are 2 things going on:
    1. The EJB3 container is automatically adding the property 'toplink.server.platform.class.name' into what is passed to TopLink to ensure the proper container is configured. I have had a bug filed to get this changed to toplink.target-server in the 10.1.3.4 patch-set.
    2. The logging by default goes into the OC4J log found in <HOME>\j2ee\home\log\oc4j
    You can re-configure OC4J to also log these messages to stdout or if you only want them to stdout you can simply set the logging-type in the persistence unit properties.
          <property name="toplink.logging.logger" value="DefaultLogger"/>Doug

  • Persistence unit is inconsistent

    Hi all,
    I have a problem with my primary key generation, my class looks as follows:
    @Entity
    @Table(name="MYAPP_M_CUST")
    public class Customer implements Serializable {
         @Id
         @Column(name="CUST_ID")
         @GeneratedValue (strategy=GenerationType.TABLE, generator="myGen")
         @TableGenerator(name = "myGen", table = "MY_GENERATOR_TABLE")
         private int custId;
    when i try to persist a new "Customer" via the entity manager i get a
    Caused by: com.sap.engine.lib.injection.InjectionException: Injection on field em of instance com.mycompany.myapp.CustServiceBean@1daef87 failed. Could not get a value to be injected from the factory.
         at com.sap.engine.lib.injection.FieldInjector.inject(FieldInjector.java:115)
         at com.sap.engine.lib.injection.InjectionMatrix.inject(InjectionMatrix.java:45)
         at com.sap.engine.services.ejb3.runtime.impl.Interceptors_DependencyInjection.invoke(Interceptors_DependencyInjection.java:22)
         ... 101 more
    Caused by: java.lang.RuntimeException: The persistence unit is inconsistent with the database schema:
    Error on attribute >>com.mycompany.myapp.Customer.custId<<: The generator table >>MY_GENERATOR_TABLE<< does not exist.
    which makes me wonder because i created the "MY_GENERATOR_TABLE" table with the following definition:
    CREATE TABLE "SAPNDWDB"."MY_GENERATOR_TABLE"
         "GEN_KEY"  Varchar (256) UNICODE  NOT NULL,
         "GEN_VALUE"  Integer,
         PRIMARY KEY("GEN_KEY")
    and I can see it via the SQL Studio.
    Without the key generation the persist works fine and writes data to the table.
    Any ideas?
    Regards,
        Christian

    Hi Christian,
    Are you running your app on the System DataSource? If so, you have to create all tables using the Java Dictionary. You find more information [here|http://help.sap.com/saphelp_nwce10/helpdata/en/45/c8baeb5f0c2e97e10000000a155369/frameset.htm].
    HTH!
    \-- Vladimir

  • NullPointerException in OC4J TP4 persistence unit predeployment

    Hi,
    I have an ee5 application that I've been developing on jboss/hibernate, and I'm now trying to deploy it to oc4j/toplink. When I deploy it to oc4j, the deployment fails with this stacktrace:
    oracle.oc4j.persistence.PersistenceException: [eTimesheet-ear:C:\oc4j\oc4j-11.1.1.0.0_tp4\j2ee\home\applications\eTimesheet-ear\eTimesheet-ejb.jar] - Exception creating EntityManagerFactory using PersistenceProvider class oracle.toplink.PersistenceProvider for persistence unit eTimesheet.
         at oracle.oc4j.persistence.PersistenceException.exceptionCreatingEntityManagerFactory(PersistenceException.java:113)
         at oracle.oc4j.persistence.PersistenceUnitManagerImpl.createContainerEntityManagerFactory(PersistenceUnitManagerImpl.java:178)
         at oracle.oc4j.persistence.PersistenceUnitManagerImpl.createPersistenceUnit(PersistenceUnitManagerImpl.java:140)
         at oracle.oc4j.persistence.PersistenceUnitManagerImpl.initialize(PersistenceUnitManagerImpl.java:80)
         at oracle.oc4j.persistence.ServerPersistenceUnitManagerImpl.initialize(ServerPersistenceUnitManagerImpl.java:17)
         at com.evermind.server.ejb.EJBPackageDeployment.initializePersistenceUnitManager(EJBPackageDeployment.java:1010)
         at com.evermind.server.ejb.EJBPackageDeployment.preLoadClasses(EJBPackageDeployment.java:1004)
         at com.evermind.server.ejb.EJBContainer.postInit(EJBContainer.java:441)
         at com.evermind.server.ApplicationStateRunning.initializeApplication(ApplicationStateRunning.java:262)
         at com.evermind.server.Application.setConfig(Application.java:538)
         at com.evermind.server.Application.setConfig(Application.java:433)
         at com.evermind.server.ApplicationServer.addApplication(ApplicationServer.java:2125)
         at oracle.oc4j.admin.internal.ApplicationDeployer.addApplication(ApplicationDeployer.java:554)
         at oracle.oc4j.admin.internal.ApplicationDeployer.doDeploy(ApplicationDeployer.java:210)
         at oracle.oc4j.admin.internal.DeployerBase.execute(DeployerBase.java:99)
         at oracle.oc4j.admin.jmx.server.mbeans.deploy.OC4JDeployerRunnable.doRun(OC4JDeployerRunnable.java:52)
         at oracle.oc4j.admin.jmx.server.mbeans.deploy.DeployerRunnable.run(DeployerRunnable.java:82)
         at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:885)
         at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907)
         at java.lang.Thread.run(Thread.java:619)
    Caused by: javax.persistence.PersistenceException: Exception [TOPLINK-28018] (Oracle TopLink - 11g Technology Preview 4 (11.1.1.0.0) (Build 080418)): oracle.toplink.exceptions.EntityManagerSetupException
    Exception Description: Predeployment of PersistenceUnit [eTimesheet] failed.
    Internal Exception: java.lang.NullPointerException
         at oracle.toplink.internal.ejb.cmp3.EntityManagerSetupImpl.predeploy(EntityManagerSetupImpl.java:790)
         at oracle.toplink.PersistenceProvider.createContainerEntityManagerFactory(PersistenceProvider.java:146)
         at oracle.oc4j.persistence.PersistenceUnitManagerImpl.createContainerEntityManagerFactory(PersistenceUnitManagerImpl.java:173)
         ... 18 more
    Caused by: Exception [TOPLINK-28018] (Oracle TopLink - 11g Technology Preview 4 (11.1.1.0.0) (Build 080418)): oracle.toplink.exceptions.EntityManagerSetupException
    Exception Description: Predeployment of PersistenceUnit [eTimesheet] failed.
    Internal Exception: java.lang.NullPointerException
         at oracle.toplink.exceptions.EntityManagerSetupException.predeployFailed(EntityManagerSetupException.java:198)
         ... 21 more
    Caused by: java.lang.NullPointerException
         at oracle.toplink.internal.ejb.cmp3.metadata.accessors.EmbeddedIdAccessor.processEmbeddableClass(EmbeddedIdAccessor.java:115)
         at oracle.toplink.internal.ejb.cmp3.metadata.accessors.EmbeddedAccessor.process(EmbeddedAccessor.java:259)
         at oracle.toplink.internal.ejb.cmp3.metadata.accessors.EmbeddedIdAccessor.process(EmbeddedIdAccessor.java:69)
         at oracle.toplink.internal.ejb.cmp3.metadata.accessors.ClassAccessor.processAccessor(ClassAccessor.java:570)
         at oracle.toplink.internal.ejb.cmp3.metadata.accessors.ClassAccessor.processAccessorFields(ClassAccessor.java:583)
         at oracle.toplink.internal.ejb.cmp3.metadata.accessors.ClassAccessor.processAccessors(ClassAccessor.java:609)
         at oracle.toplink.internal.ejb.cmp3.metadata.accessors.ClassAccessor.process(ClassAccessor.java:510)
         at oracle.toplink.internal.ejb.cmp3.metadata.MetadataProcessor.processAnnotations(MetadataProcessor.java:279)
         at oracle.toplink.internal.ejb.cmp3.persistence.PersistenceUnitProcessor.processORMetadata(PersistenceUnitProcessor.java:266)
         at oracle.toplink.internal.ejb.cmp3.EntityManagerSetupImpl.predeploy(EntityManagerSetupImpl.java:747)
         ... 20 more
    I probably shouldn't jump to conclusions, but since this is a nullpointer exception and my code runs ok on hibernate, I suspect this is a bug in toplink.
    Thoughts?

    I turned on FINEST logging, and it appears that this exception is thrown when processing the following class (trimmed irrelevant parts):
    @Entity
    @Table(name = "PS_HRLY_APPRVR_VW")
    @NamedQueries({ ... })
    public class ApproverAssignment implements Serializable
    @Embeddable
    public static class ApproverAssignmentPK implements Serializable
    @Embedded
    @AttributeOverride(name = "employeeId", column =
    @Column(name = "emplid", updatable = false))
    private EmployeeId workerId;
    @Embedded
    @AttributeOverride(name = "employeeId", column =
    @Column(name = "supervisor_id", updatable = false))
    private EmployeeId approverId;
    @Override
    public int hashCode()
    @Override
    public boolean equals(Object obj)
    @EmbeddedId
    private ApproverAssignmentPK approverAssignmentPK = new ApproverAssignmentPK();
    ...getters/setters
    Also, here's the source code for EmployeeId:
    @Embeddable
    public class EmployeeId implements Serializable
    private static final long serialVersionUID = 1L;
    @Length(max=10, min=9)
    private String employeeId;
    //for JPA
    protected EmployeeId()
    protected EmployeeId(String employeeId)
    this.employeeId = employeeId;
    public String getEmployeeId()
    return employeeId;
    @Override
    public int hashCode()
    @Override
    public boolean equals(Object obj)
    @ConstructsFromString
    public static EmployeeId valueOf(String employeeId)
    Preconditions.checkNotNull(employeeId, "employeeId is null");
    return new EmployeeId(employeeId);
    Maybe toplink doesn't like nested @Embeddables? I thought they were legal, but maybe I'm wrong.
    Thanks

  • Abstract Entity classes with Collections

    I trying to figure out a way to have a generics collection in a parent collection that can hold various entity types of the same super-class.
    One thing I've tried was the following:
    @Entity
    public class ParentEnt implements Serializable {
        private static final long serialVersionUID = 1L;
        @Id
        @GeneratedValue(strategy = GenerationType.AUTO)
        private Long id;
        @Column
        private String parentName;
        @OneToMany(mappedBy="parentEnt")
        private Collection<ChildAbs> children;
        /* Methods removed */
    @Entity
    public abstract class ChildAbs implements java.io.Serializable {
        protected static final long serialVersionUID = 1L;
        @Id
        protected Long id;
        @ManyToOne
        protected ParentEnt parentEnt;
        /* Methods removed */
    @Entity
    public class ChildEnt extends ChildAbs implements Serializable {
        @Column
        protected String childName;
    }but this is the error I get:
    Exception [TOPLINK-30005] (Oracle TopLink Essentials - 2.0 (Build b58g-fcs (09/07/2007))): oracle.toplink.essentials.exceptions.PersistenceUnitLoadingException
    Exception Description: An exception was thrown while searching for persistence archives with ClassLoader: sun.misc.Launcher$AppClassLoader@11b86e7
    Internal Exception: javax.persistence.PersistenceException: Exception [TOPLINK-28018] (Oracle TopLink Essentials - 2.0 (Build b58g-fcs (09/07/2007))): oracle.toplink.essentials.exceptions.EntityManagerSetupException
    Exception Description: predeploy for PersistenceUnit [testPU] failed.
    Internal Exception: Exception [TOPLINK-7250] (Oracle TopLink Essentials - 2.0 (Build b58g-fcs (09/07/2007))): oracle.toplink.essentials.exceptions.ValidationException
    Exception Description: [class test.ParentEnt] uses a non-entity [class test.ChildAbs] as target entity in the relationship attribute [private java.util.Collection test.ParentEnt.children].So, it looks like there is no way to have a generics collection for an abstract entity class. Is there another way to accomplish what I want using a generics collection?
    Additionally, entity ChildEnt generates an error due to the abstract class' id property not carrying forward (see Abstract Entities: http://java.sun.com/javaee/5/docs/tutorial/doc/bnbqa.html#bnbqo)
    Exception Description: Entity class [class testprintservices.ChildEnt] has no primary key specified. It should define either an @Id, @EmbeddedId or an @IdClass.Any input would be appreciated.

    As far as my first question, I was trying to make my collection so it can hold various type of entity classes, but now that I think about it, it was a bad idea. For instance, being able to hold ChildEnt and ChildEnt2 in the same collection. If JPA did allow this, it might be possible to save the entities to the DB, but the reverse wouldn't be possible.
    Ok, regarding my 2nd question: I don't understand why having it as @Entity wouldn't. The links (mine and yours) clearly shows that @Id is carried forward in the example they provide. Anyway, since I can't use the superclass in the collection, this is pointless. I'll use the suggested annotation.
    Thanks.

  • Multiple persistence units not supported by OEPE 12.1.1.0.1

    Dear Friends -
    Environment
    Oracle Enterprise Pack for Eclipse 12.1.1.0.1
    JPA version : 2.0
    Platform : Eclipse link 2.3.x
    OWLS Version : 12c (12.1.1)
    JDK : jrockit1.6
    Sybase database.
    While developing JPA projects, we are getting error and warning while using Multiple persistence units in persistence.xml.
    Steps :
    1. Create 2 persistence unit in persistence.xml.
    -- Warning saying that "Multiple persistence units defined - only the first persistence unit will be recognized"
    2. Create 2 database connection in OEPE.
    3. Create JPA Entities from Table using first database connection.
    -- No issues.
    4. Create another JPA Entities from Table using second database connection.
    -- Issue is entities created in step3.(is first JPA Entity classes)
    -- Errors from first JPA Entity classes.
    ----1. Table "table_name1" cannot be resolved.
    ----2. Table "table_name1" for column "column_name1" is not valid for this entity.
    5. Second JPA Entity classes are fine.
    Thanks
    Justin.
    Sample persistence.xml
    <?xml version="1.0" encoding="UTF-8"?>
    <persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
         <persistence-unit name="PU1" transaction-type="JTA">
              <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
              <jta-data-source>DS1</jta-data-source>
              <class>com.test.FirstEntity</class>     
         </persistence-unit>
         <persistence-unit name="PU2" transaction-type="JTA">
              <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
              <jta-data-source>DS2</jta-data-source>
              <class>com.test.SecondEntity</class>
         </persistence-unit>
    </persistence>

    Also, the reason you are seeing those errors in your first project after generating entities from the second connection is because the project wide schema is being updated to the second connections generation schema. If you go into the JPA project properties you can change it back. This workflow would need to change with multiple persistence unit support.
    Neil

Maybe you are looking for