Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JPA JSE EntityListener and Singleton

 
Ranch Hand
Posts: 153
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Hello I have a JSE Application using JPA 2.1
I have run into a curious problem.
I am using an EntityListener for auditing purposes



This listener is dependent on UserService.
I have tried to make that a Singleton:



This in turn uses PersistenceService (which should be a singleton too ...) and which should provide one and only one instance of the EntityManagerFactory
to the application:



When I run tests I see that a lot of instances of these "Singletons" are created until the application crashes because all connections to the database are used up.
When I remove the EntityListener this behavior stops, but I really need the AuditListener
What is going on? And how can I correct this problem?



Many thanks for any hints
 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Locking this one since this got answered in your other topic here https://coderanch.com/t/635105/java/java/Singleton.
 
Honk if you love justice! And honk twice for tiny ads!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
    Bookmark Topic Watch Topic
  • New Topic