Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » desktop Swing application with EclipseLink
desktop Swing application with EclipseLink [message #727803] Wed, 21 September 2011 21:12 Go to next message
Marc is currently offline Marc
Messages: 25
Registered: July 2009
Junior Member
I've started learning jpa and EclipseLink only few days ago, and till now i've succeeded to understand the basics of the API, but still don't feel able to build a serious application that can stand for long.

The problem is that i didn't find any articles that gives enough informations about some good practices/design patterns, that match the kind of applications i'm trying to build. I've found some articles talking about jpa in standalone applications, but still were dealing with clients and servers and using sessions, something that confuses me.

So just to make my self clear, the application i'm about to develop doesn't need any client or server or any kind of network communication, it's a mono-user Swing application, on which i intend to use EclipseLink with the Derby Embedded database. The application isn't a small one, it will have to deal with roughly 30 entities ...

I was thinking about creating one EntityManager at the start of the application, and to perform all my transactions through it until the application shutdowns, but after some researchs i figured out that such a solution may have performance issues ... creating an EntityManager and closing it on each transaction doesn't seem to be a good idea neither.

I need some indications that can put me in the right way, so any kind of help (tips, links ...) will be very appreciated.

Thanks
Re: desktop Swing application with EclipseLink [message #727861 is a reply to message #727803] Thu, 22 September 2011 01:22 Go to previous messageGo to next message
Tom Eugelink is currently offline Tom Eugelink
Messages: 806
Registered: July 2009
Senior Member
I've written a fairly large Swing application (40 concurrent users, 100 entities) on top of an Informix database. The biggest thing with entity manager here, is how to user expects the application to behaves. I found that one EM per window (JFrame) is the most logical setup. (And one EntityManagerFactor per application.)

This means that you load entities once for each window. Modifications stay withing the window until they are saved.

Because you have multiple EMF's, you need to disable the second level cache.

Tom



On 2011-09-22 03:12, Marc wrote:
> I've started learning jpa and EclipseLink only few days ago, and till now i've succeeded to understand the basics of the API, but still don't feel able to build a serious application that can stand for long.
>
> The problem is that i didn't find any articles that gives enough informations about some good practices/design patterns, that match the kind of applications i'm trying to build. I've found some articles talking about jpa in standalone applications, but still were dealing with clients and servers and using sessions, something that confuses me.
>
> So just to make my self clear, the application i'm about to develop doesn't need any client or server or any kind of network communication, it's a mono-user Swing application, on which i intend to use EclipseLink with the Derby Embedded database. The application isn't a small one, it will have to deal with roughly 30 entities ...
>
> I was thinking about creating one EntityManager at the start of the application, and to perform all my transactions through it until the application shutdowns, but after some researchs i figured out that such a solution may have performance issues ... creating an EntityManager and closing it on each transaction doesn't seem to be a good idea neither.
>
> I need some indications that can put me in the right way, so any kind of help (tips, links ...) will be very appreciated.
>
> Thanks
Re: desktop Swing application with EclipseLink [message #727994 is a reply to message #727803] Thu, 22 September 2011 07:02 Go to previous messageGo to next message
Marc  is currently offline Marc
Messages: 12
Registered: September 2011
Junior Member
Thanhs for taking the time to answer Smile

As i already mentioned my application doesn't need to deal with users concurrency, it will deal with only one user. Also there won't be many frames, there will be only one which will handle six Tabs (JTabbedPane) and some modal dialogs for configuring user preferences.

Quote:
This means that you load entities once for each window.

Does this mean in my case that i should use the same entity manager from the point the application starts until it shutdowns, won't this have performance issues? I mean as you certainly know in application managed persistence context have an extended state which will keep each loaded entity instance in the managed state even after committing transactions, the application may end up loading all the database in memory ...
I also read in some forums that using the same entity manager for long term isn't safe, the database connection may drop due to various factors.

Best Regards
Marc

[Updated on: Thu, 22 September 2011 07:03]

Report message to a moderator

Re: desktop Swing application with EclipseLink [message #727996 is a reply to message #727994] Thu, 22 September 2011 07:06 Go to previous messageGo to next message
Marc  is currently offline Marc
Messages: 12
Registered: September 2011
Junior Member
And by the way i won't need many EMFs, i'll need only one.
Re: desktop Swing application with EclipseLink [message #728000 is a reply to message #727803] Thu, 22 September 2011 07:02 Go to previous messageGo to next message
Marc is currently offline Marc
Messages: 25
Registered: July 2009
Junior Member
Thanhs for taking the time to answer :)

As i already mentioned my application doesn't need to deal with users concurrency, it will deal with only one user. Also there won't be many frames, there will be only one which will handle six Tabs (JTabbedPane) and some modal dialogs for configuring user preferences.

Quote:
> This means that you load entities once for each window.

Does this mean in my case that i should use the same entity manager from the point the application starts until it shutdowns, won't this have performance issues. I mean as you certainly know in application managed persistence context have an extended state which will keep each loaded entity instance in the managed state even after committing transactions, the application may end up loading all the database in memory ...
I also read in some forums that using the same entity manager for long term isn't safe, the database connection may drop due to various factors.

Best Regards
Marc
Re: desktop Swing application with EclipseLink [message #728011 is a reply to message #727994] Thu, 22 September 2011 07:18 Go to previous messageGo to next message
Tom Eugelink is currently offline Tom Eugelink
Messages: 806
Registered: July 2009
Senior Member
> Quote:
>> This means that you load entities once for each window.
>
> Does this mean in my case that i should use the same entity manager from the point the application starts until it shutdowns, won't this have performance issues. I mean as you certainly know in application managed persistence context have an extended state which will keep each loaded entity instance in the managed state even after committing transactions, the application may end up loading all the database in memory ...
> I also read in some forums that using the same entity manager for long term isn't safe, the database connection may drop due to various factors.

Basically yes. But I clear the EM on every save action (commit to database) in order to force a reload of the entities. Screens stay open a whole working day, and we have not had any problems.
But you could consider closing the EM and creating a new one when saving. This will give you caching during regular use, and a save will clear all.

Eclipselink SHOULD automatically create new connections if existing ones are unusable, but I have not been able to make that work. As a coincidence I'm just trying to figure that one out, again. Some time back we have had problems with MySQL connections being dropped and then still reused (I made some posts about that on this newgroup). And now I'm in a similar situation with Informix.

You still need to disable the 2nd level cache, so a clear or new EM will pull the changes from the database (made by other users via their Swing application) and not from the EMF's cache.

Tom
Re: desktop Swing application with EclipseLink [message #728012 is a reply to message #727996] Thu, 22 September 2011 07:20 Go to previous messageGo to next message
Tom Eugelink is currently offline Tom Eugelink
Messages: 806
Registered: July 2009
Senior Member
On 22-9-2011 13:06, Marc wrote:
> And by the way i won't need many EMFs, i'll need only one.

I know, but unlike server based Eclipselink (EJB), where there really is only one EMF in the whole ecosystem, you'll have one-per-swing-application. So you do want caching by the EM, but not by the EMF.

Tom
Re: desktop Swing application with EclipseLink [message #728034 is a reply to message #727803] Thu, 22 September 2011 08:35 Go to previous messageGo to next message
Gordon Yorke is currently offline Gordon Yorke
Messages: 77
Registered: July 2009
Member
Hello,
For the isolated Derby Database I would also suggest investigating the persistence unit property "eclipselink.persistence-context.reference-mode" = "WEAK" . Using this mode should alleviate any memory management issues when using a long lived Entity Manager in a desktop application environment. This will allow you to reference the Managed Entities directly in the application and not require EntityManager.clear() calls to clear the EM.

In a networked environment if the application would benefit from caching to alleviate demand on the database cache co-ordination is still an option with a desktop application, although you may need to consider total network traffic. (ie co-ordinate more static data but use @Cacheable false for volatile data.)

--Gordon
Re: desktop Swing application with EclipseLink [message #728037 is a reply to message #728012] Thu, 22 September 2011 08:41 Go to previous messageGo to next message
Marc  is currently offline Marc
Messages: 12
Registered: September 2011
Junior Member
Quote:
Basically yes. But I clear the EM on every save action (commit to database)

It sounds to be a good solution. The detach()method may be useful too.

Quote:
But you could consider closing the EM and creating a new one when saving.

I think i'll use the first alternative, since AFAIK closing and re-opening when ever i need access to the database may be expensive.

Concerning the connection drop, i hope you'll keep me in touch if you find out a solution.

And finally concerning the 2nd level cache, i'm trying to get some informations about.

Re: desktop Swing application with EclipseLink [message #728175 is a reply to message #728037] Thu, 22 September 2011 13:01 Go to previous messageGo to next message
Marc  is currently offline Marc
Messages: 12
Registered: September 2011
Junior Member
For now i've set the following properties:
<property name="eclipselink.persistence-context.reference-mode" value="WEAK" />
<property name="eclipselink.cache.shared.default" value="false"/>

However after checking this reference, i discovered the property "eclipselink.cache.size.default" which i plan to set to some kilos, so why should i bother myself clearing the EntityManager, while i'm able to control the maxmum size of the allowed cache for EclipseLink. Am-i missunderstanding the property?

_____________________________________________


@Gordon Thanks for the contribution
Quote:
In a networked environment if the application would benefit from caching to alleviate demand on the database cache co-ordination is still an option with a desktop application, although you may need to consider total network traffic. (ie co-ordinate more static data but use @Cacheable false for volatile data.)

I didn't understand much of this, could you explain more please. Knowing that i have no network traffic, do you think i should take more time to learn about coordination before starting to code?
Re: desktop Swing application with EclipseLink [message #728176 is a reply to message #728175] Thu, 22 September 2011 13:03 Go to previous messageGo to next message
Marc  is currently offline Marc
Messages: 12
Registered: September 2011
Junior Member
this is the link i couldn't use on my previous post(it requires 5 messages at least)
(no subject) [message #728197 is a reply to message #728037] Thu, 22 September 2011 13:01 Go to previous messageGo to next message
Marc is currently offline Marc
Messages: 25
Registered: July 2009
Junior Member
For now i've set the following properties:
<property name="eclipselink.persistence-context.reference-mode" value="WEAK" />
<property name="eclipselink.cache.shared.default" value="false"/>

However after checking this reference, i discovered the property "eclipselink.cache.size.default" which i plan to set to some kilos, so why should i bother myself clearing the EntityManager, while i'm able to control the maxmum size of the allowed cache for EclipseLink. Am-i missunderstanding the property?

_____________________________________________


@Gordon Thanks for the contribution
Quote:
> In a networked environment if the application would benefit from caching to alleviate demand on the database cache co-ordination is still an option with a desktop application, although you may need to consider total network traffic. (ie co-ordinate more static data but use @Cacheable false for volatile data.)

I didn't understand much of this, could you explain more please. Knowing that i have no network traffic, do you think i should take more time to learn about coordination before starting to code?
Re: (no subject) [message #728275 is a reply to message #728176] Thu, 22 September 2011 17:04 Go to previous messageGo to next message
Marc  is currently offline Marc
Messages: 12
Registered: September 2011
Junior Member
One more question: I'm using eclipse indigo for EE developement, just to take benefit from the JPA project support. I created a JPA project and in the persistence.xml file i set <property name="eclipselink.cache.shared.default" value="false"/>, a warning appears :
"eclipselink.cache.shared.default" is a legacy entity caching property. Consider migration to JPA 2.0 and EclipseLink cache settings via annotation or XML.mapping file

I'm using the last release of eclipseLink (2.3.0), and here's a link to EclipseLink wiki, where there's an example for setting the property onto the persistence.xml file, so what's wrong? what could be the reason of the warning?

Note that i used the same property in a normal java project, and there were no warnings, it appeared only when used the JPA project.

[Updated on: Thu, 22 September 2011 17:22]

Report message to a moderator

Re: (no subject) [message #728279 is a reply to message #728176] Thu, 22 September 2011 17:04 Go to previous messageGo to next message
Marc is currently offline Marc
Messages: 25
Registered: July 2009
Junior Member
One more question: I'm using eclipse indigo for EE developement, just to take benefit from the JPA project support. I created a JPA project and in the persistence.xml file i set <property name="eclipselink.cache.shared.default" value="false"/>, a warning appears :
"eclipselink.cache.shared.default" is a legacy entity caching property. Consider migration to JPA 2.0 and EclipseLink cache settings via annotation or XML.mapping file
I'm using the last release of eclipseLink (2.3.0), and http://wiki.eclipse.org/Using_EclipseLink_JPA_Extensions_%28ELUG%29#How_to_Use_the_Persistence_Unit_Properties_for_Caching's a link to EclipseLink wiki, where there's an example for setting the property onto the persistence.xml file, so what's wrong? what could be the reason of this warning?

Note that i used the same property in a normal java project, and there were no warnings, it appeared only when used the JPA project.
Re: desktop Swing application with EclipseLink [message #728349 is a reply to message #728175] Fri, 23 September 2011 00:48 Go to previous messageGo to next message
Tom Eugelink is currently offline Tom Eugelink
Messages: 806
Registered: July 2009
Senior Member
> @Gordon Thanks for the contribution
> Quote:
>> In a networked environment if the application would benefit from caching to alleviate demand on the database cache co-ordination is still an option with a desktop application, although you may need to consider total network traffic. (ie co-ordinate more static data but use @Cacheable false for volatile data.)
>
> I didn't understand much of this, could you explain more please. Knowing that i have no network traffic, do you think i should take more time to learn about coordination before starting to code?

Cache co-ordination are ways to still use the cache by, for example, only allowing certain low frequently modified entities to be cached. This requires not blunt usage of the cache, but coordinated use. A more advanced approach would be distributed caching, where caches are synced between Swing clients separately from the database. A interesting intermediate step would be to purge the cache in every client of all copies of an entity, if one client commits a change to that entity. Does Eclipselink have support for this, Gordon?

Tom
Re: desktop Swing application with EclipseLink [message #728488 is a reply to message #728349] Fri, 23 September 2011 06:57 Go to previous messageGo to next message
Marc  is currently offline Marc
Messages: 12
Registered: September 2011
Junior Member
Thanks for the explanation Tom.

I've passed through cache coordination while reading EclipseLink documentation, here and here but didn't go deeply.

One more question:
Are there a relationship between managed entities and cached entities? I mean for example is it possible that an entity is managed and not cached at the same time?
(no subject) [message #728503 is a reply to message #728349] Fri, 23 September 2011 06:57 Go to previous messageGo to next message
Marc is currently offline Marc
Messages: 25
Registered: July 2009
Junior Member
Thanks for the explanation Tom.

I've passed through cache coordination while reading EclipseLink documentation, http://wiki.eclipse.org/Introduction_to_Cache_%28ELUG%29#Cache_Coordination_2 and http://wiki.eclipse.org/EclipseLink/UserGuide/JPA/sandbox/caching/Cache_Coordination but didn't go deeply.

One more question:
Are there a relationship between managed entities and cached entities? I mean for example is it possible that an entity is managed and not cached at the same time?
Re: (no subject) [message #729021 is a reply to message #728488] Sat, 24 September 2011 15:03 Go to previous messageGo to next message
Marc  is currently offline Marc
Messages: 12
Registered: September 2011
Junior Member
Quote:
I'm using the last release of eclipseLink (2.3.0), and here's a link to EclipseLink wiki, where there's an example for setting the property onto the persistence.xml file, so what's wrong? what could be the reason of the warning?


The warning is due to that JPA 2.0 requires to set <shared-cache-mode> element to NONE under the persistence-unit element (instead of "eclipselink.cache.shared.default" property), hope this will help somebody.

However I noticed that disabling 2nd-Level caching leads to another warning if I try to set other caching properties (such as "eclipselink.cache.size.default" property) ==> Does this mean that all caching properties are affecting only 2nd-Level cache? Same question concerning @Cache and @Cacheable annotations?

[Updated on: Sat, 24 September 2011 16:57]

Report message to a moderator

Re: (no subject) [message #729337 is a reply to message #729021] Sun, 25 September 2011 19:35 Go to previous message
Marc  is currently offline Marc
Messages: 12
Registered: September 2011
Junior Member
I gotta stop answering my self Very Happy. Concerning cache properties on persistence.xml file and the @cache and the @Cacheable all of them are for L2 Cache not for L1, hope this will help someone Smile.

[Updated on: Sun, 25 September 2011 19:37]

Report message to a moderator

Re: (no subject) [message #729340 is a reply to message #729021] Sun, 25 September 2011 19:35 Go to previous message
Marc is currently offline Marc
Messages: 25
Registered: July 2009
Junior Member
I gotta stop answering my self :d. Concerning the @cache and the @Cacheable both are for L2 Cache not for L1, hope this will help someone :).
Re: (no subject) [message #729341 is a reply to message #729021] Sun, 25 September 2011 19:35 Go to previous message
Marc is currently offline Marc
Messages: 25
Registered: July 2009
Junior Member
I gotta stop answering my self :d. Concerning the @cache and the @Cacheable both are for L2 Cache not for L1, hope this will help someone :).
Previous Topic:Sybase Connection logs in as guest in case of Connection communication failure
Next Topic:Tool to run JPQL queries
Goto Forum:
  


Current Time: Thu Jul 24 06:57:20 EDT 2014

Powered by FUDForum. Page generated in 0.02307 seconds