You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@netbeans.apache.org by Sean Carrick <se...@pekinsoft.com> on 2020/12/12 15:56:07 UTC

EclipseLink Persistence in Platform Development

Hey All!

I am working on a platform project that is using Derby/Embedded as the
database. I have created a Persistence Unit XML file and the Entity
models within one of my project modules. However, I am unable to access
the database in this manner and have a question regarding this issue.

I have looked at the CRUD tutorial and noticed that it uses EclipseLink
to access the sample Derby database from a standard J2SE project, which
it then wraps into a library module for inclusion in the platform
project. Is this the only way to accomplish the persistence
capabilities? The reason that I am asking this is because I created the
Entity classes directly within one of my modules, as well as the
`persistence.xml` file. My module project structure is:

Source Packages
     - META-INF
         - persistence.xml
      - com.pekinsoft.nwind.db.api
         - AccountTypes.java
         - Accounts.java
         - etc.

After setting up this structure, I added a package
`com.pekinsoft.nwind.db.admin`, into which I have added a TopComponent,
which has a BeanTreeView on it for displaying the records from the
AccountTypes table in the database. In the constructor of the
TopComponent, I have placed the following code:

EntityManager entityManager = Persistence.createEntityManagerFactory(
         "NorthwindDBLibraryPU").createEntityManager();
Query query = entityManager.createNamedQuery("AccountTypes.findAll");
List<AccountTypes> resultList = query.getResultList();
em.setRootContext(new AbstractNode(Children.create(new
AccountTypeChildFactory(resultList), true)));

When I run the application, I receive the following exception:

A java.lang.IllegalStateException exception has occurred.
         Click Show Details or see the messages.log file located in your
/home/sean/Projects/Northwind-Main/Northwind/build/testuserdir/var/log
folder.

The top line of the stacktrace is (the whole thing is pretty long):

java.lang.IllegalStateException: Cannot find TopComponent with
preferredID AccountTypesTopComponent, see IDE log for more details.

Going off of this exception, it appears that there is not a TopComponent
with the preferredID of AccountTypesTopComponent, but my annotations on
the TopComponent are as follows:

@ConvertAsProperties(
                 dtd = "-//com.pekinsoft.nwind.db.admin//AccountTypes//EN",
                 autostore = false
)
@TopComponent.Description(
                 preferredID = "AccountTypesTopComponent",
                 iconBase = "com/pekinsoft/nwind/db/admin/database16.png",
                 persistenceType = TopComponent.PERSISTENCE_ALWAYS
)
@TopComponent.Registration(mode = "explorer", openAtStartup = false)
@ActionID(category = "Window", id =
"com.pekinsoft.nwind.db.admin.AccountTypesTopComponent")
@ActionReference(path = "Menu/Window/DB Tools" /*, position = 333 */)
@TopComponent.OpenActionRegistration(
                 displayName = "#CTL_AccountTypesAction",
                 preferredID = "AccountTypesTopComponent"
)
@Messages({
         "CTL_AccountTypesAction=Account Types",
         "CTL_AccountTypesTopComponent=Account Types Explorer",
         
"HINT_AccountTypesTopComponent=Lists all of the set account types"
})

You can plainly see that the preferredID is set to
AccountTypesTopComponent. Also, I commented out all of the persistence
code from the constructor, ran the application and the TopComponent
displayed as expected. Therefore, I uncommented each line, one at a
time, and ran the application. The TopComponent displayed as expected
until I uncommented the line:

Query query = entityManager.createNamedQuery("AccountTypes.findAll");

When I ran the application after uncommenting this line, that is when I
would get the exception thrown. I do not understand why that would be.
So, I started looking at my persistence.xml file and everything seems
correct. Then I looked at my Entity classes and notice that the
`@Entity` annotation was underlined with a yellow squiggly line. When I
hovered over it, the message was "The project does not contain a
persistence unit." Yet, the persistence.xml is in the META-INF package.

I am confused as to what is going on and why my Entity classes cannot
see the persistence unit in the META-INF package.

With all of that explained, I once again ask, can persistence using
EclipseLink not be contained directly in a module project? Must it be in
a standard J2SE project wrapped as a Library Module? If this is the
case, why is that?

Thank you all for your assistance. I do truly appreciate it!

-SC


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@netbeans.apache.org
For additional commands, e-mail: users-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists