Hi Miro,
I am not so familiar with JPA specification but this code is generated
automatically from NetBeans 6 (Sun Reference Implementation for Java
BluePrints and future IDEs) using TopLink (Sun/Oracle Reference
Implementation for JPA) and with TopLink it is working fine. For the
current case I can answer you why clear() is called but I think that
this is not a problem.
Jan Stola from Sun is more involved in BeansBinding technology and
maybe he can explain in more details why JPA specification have to
support clear() in this situation.
We display the query result in JTable using Beans Binding. We allow to
edit the content of the list and Beans Binding automatically propagates
these changes into the view (JTable). We allow to add/remove/refresh the
items in the list - that's why we expect the list to be modifiable.
Hence, I think that it is not a good design decision to return all
result lists unmodifiable. Note that other JPA providers (TopLink and
Hibernate) don't do that. It may work well in J2EE applications, but it
is annoying in standalone J2SE applications.
To Miro: Today I added 'modifiableWrapper' property to query result list
in NetBeans (in trunk, not in NetBeans 6.0 branch). So, it is sufficient
to check this property to force the GUI builder to generate modifiable
wrapper around unmodifiable list returned by JPA. If you want to use
NetBeans 6.0 then you have to add the modifiable wrapper manually:
1. Select query result list in Inspector window (list node under Other
Components node).
2. Invoke Customize Code action from the contextual menu.
3. Switch combo-box on the left side of the dialog from "default code"
to "custom creation".
4. Change 'query.getResultList()' part of the creation code to 'new
java.util.LinkedList(query.getResultList())'
5. Press OK.
Honza
Patrick Linskey wrote:
Hi,
Why is the clear() being called? The thing is, query return results
are read-only; mutating the results doesn't really make sense. What
would you expect the result of calling clear() to be?
-Patrick
On Nov 11, 2007 12:50 AM, Miroslav Nachev <[EMAIL PROTECTED]> wrote:
The application is very simple. It is created automatically using NetBeans
"New Project" and then "Database Desktop Application". By default it use
TopLink and everything is working fine. When I change the EntityManager to
OpenJPA in "persistence.xml" it is working in different way (not working
properly) and this exception is thrown on refresh and when I try to create
new record in detailTable.
I forgot to inform you that I am created 2 tables which are related:
MainTable and DetailTable. In current case MainTable are Persons and
DetailTable are Person Address Details.
I can send you the project in WinRAR format or ZIP but you can create it
your self also getting the last NetBeans from NetBeans 6 Development
Downloads <http://www.netbeans.info/downloads/dev.php>.
47 address_bookPU INFO [AWT-EventQueue-0] openjpa.Runtime - Starting
OpenJPA 1.1.0-SNAPSHOT
188 address_bookPU INFO [AWT-EventQueue-0] openjpa.jdbc.JDBC - Using
dictionary class "org.apache.openjpa.jdbc.sql.MySQLDictionary".
516 address_bookPU INFO [AWT-EventQueue-0] openjpa.Enhance - Creating
subclass for "[class test.Persons, class test.AddressDetails]". This means
that your application will be less efficient and will consume more memory
than it would if you ran the OpenJPA enhancer. Additionally, lazy loading
will not be available for one-to-one and many-to-one persistent attributes
in types using field access; they will be loaded eagerly instead.
data: [EMAIL PROTECTED]
2007-11-11 10:41:23 org.jdesktop.application.Task failed
SEVERE: [EMAIL PROTECTED] failed:
java.lang.UnsupportedOperationException: Result lists are read-only.
java.lang.UnsupportedOperationException: Result lists are read-only.
at org.apache.openjpa.lib.rop.AbstractResultList.readOnly(
AbstractResultList.java:43)
at org.apache.openjpa.lib.rop.AbstractResultList.clear(
AbstractResultList.java:80)
at org.apache.openjpa.kernel.DelegatingResultList.clear(
DelegatingResultList.java:236)
at
org.jdesktop.observablecollections.ObservableCollections$ObservableListImpl.clear
(ObservableCollections.java:324)
at test.DesktopApplication1View$RefreshTask.doInBackground(
DesktopApplication1View.java:272)
at test.DesktopApplication1View$RefreshTask.doInBackground(
DesktopApplication1View.java:247)
at org.jdesktop.swingworker.SwingWorker$1.call(Unknown Source)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java
:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at org.jdesktop.swingworker.SwingWorker.run(Unknown Source)
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)
Miro.
On 11/10/07, Patrick Linskey <[EMAIL PROTECTED]> wrote:
Can you post the full stack trace?
-Patrick
On Nov 10, 2007 12:38 PM, Miroslav Nachev <[EMAIL PROTECTED]> wrote:
Hi,
I try to use OpenJPA together with NetBeans 6 and I have the following
exception:
"java.lang.UnsupportedOperationException: Result lists are read-only."
This exception is not thrown when I am using TopLink.
Can you suggest me how to set permanently all result lists to be
writable by
default?
Miro.
--
Patrick Linskey
202 669 5907