Fixing “Could not resolve a persistence unit…” errors when PU is specified, found

后端 未结 3 1760
名媛妹妹
名媛妹妹 2021-01-18 00:15

I\'m running Glassfish 3.1-SNAPSHOT as of today (2010-11-12).

I\'m using the embedded EJBContainer.

On the classpath, as reported by the EJBContainer, I have

相关标签:
3条回答
  • 2021-01-18 00:37

    I faced the same problem. The error was in the name of one of my unitName

    unitName="PUname error in one of my classes"
    
    0 讨论(0)
  • 2021-01-18 00:48

    If by mistake you put @PersistenceContext(name="cx") instead of @PersistenceContext(unitName="cx") you get the same error with everything else working.

    0 讨论(0)
  • 2021-01-18 00:57

    This one is a combination of weird behavior and pilot error.

    First, the pilot error.

    The particular JUnit test case I was looking at was that of a colleague, and it was named as though it were an EJB itself, following our internal naming convention. This is probably a cut and paste error on my colleague's part.

    I mention that because every time I opened the file I stared at it as though it itself were an EJB.

    But of course it is not an EJB.

    However, mysteriously, there is a @PersistenceContext annotation in there, and an EntityManager, which is unused. The persistence context has an attribute of--you guessed it--unitName="cx".

    So the strange behavior is that somewhere in between the old EJB container, which ran this test case fine, and now, the EJB container began treating this non-EJB, non-special class as a valid target for @PersistenceContext injection. Perhaps this test case is being treated as a managed bean, but I was under the impression that managed beans in a non-CDI environment had to be annotated as such.

    Anyhow, once I removed this spurious @PersistenceContext annotation, everything worked fine.

    0 讨论(0)
提交回复
热议问题