Issue 598 in google-guice: Persist Extension: PersistService.start() cannot be called multiple times

38 views
Skip to first unread message

google...@googlecode.com

unread,
Feb 2, 2011, 4:07:00 AM2/2/11
to google-g...@googlegroups.com
Status: New
Owner: ----

New issue 598 by michal.g...@gmail.com: Persist Extension:
PersistService.start() cannot be called multiple times
http://code.google.com/p/google-guice/issues/detail?id=598

The PersistService.start() method claims that it is possible to call this
method multiple times. The implementation however
throws "java.lang.IllegalStateException: Persistence service was already
initialized." on second call.

This is a problem since it is not possible to determine if the service was
already started. Moreover the PersistFilter starts the PersistService in
initialization. Therefore it is not possible to use the persistence in any
ServletContextListener!

google...@googlecode.com

unread,
Feb 7, 2011, 11:16:44 PM2/7/11
to google-g...@googlegroups.com

Comment #1 on issue 598 by dha...@google.com: Persist Extension:
PersistService.start() cannot be called multiple times
http://code.google.com/p/google-guice/issues/detail?id=598

We can add a simple isActive() method, would that solve the issue for you?

google...@googlecode.com

unread,
Feb 8, 2011, 2:50:43 AM2/8/11
to google-g...@googlegroups.com

Comment #2 on issue 598 by michal.g...@gmail.com: Persist Extension:
PersistService.start() cannot be called multiple times
http://code.google.com/p/google-guice/issues/detail?id=598

Well that would be nice. However this will not solve the problem when the
PersistService is already started in some ServletContextListener. What
about adding this check to the PersistFilter:

public void init(FilterConfig filterConfig) throws ServletException {
if (! persistService.isActive()) { // <--
persistService.start();
}
}


google...@googlecode.com

unread,
Feb 18, 2011, 9:52:56 AM2/18/11
to google-g...@googlegroups.com

Comment #3 on issue 598 by sberlin: Persist Extension:
PersistService.start() cannot be called multiple times
http://code.google.com/p/google-guice/issues/detail?id=598

Issue 605 has been merged into this issue.

google...@googlecode.com

unread,
Feb 21, 2011, 10:34:42 PM2/21/11
to google-g...@googlegroups.com
Updates:
Labels: Extension-Persist

Comment #4 on issue 598 by sberlin: Persist Extension:

PersistService.start() cannot be called multiple times
http://code.google.com/p/google-guice/issues/detail?id=598

(No comment was entered for this change.)

google...@googlecode.com

unread,
Apr 18, 2011, 5:01:52 AM4/18/11
to google-g...@googlegroups.com

Comment #5 on issue 598 by psa...@gmail.com: Persist Extension:
PersistService.start() cannot be called multiple times
http://code.google.com/p/google-guice/issues/detail?id=598

There is another related problem:

Sequence start() -> stop() -> start() throws the same exception even if the
restart should be possible.

The reason is that start checks for the emFactory to be null but it is
never reset on stop().


public synchronized void start() {
Preconditions.checkState(null == emFactory, "Persistence service was
already initialized.");
...
}

public synchronized void stop() {
Preconditions.checkState(emFactory.isOpen(), "Persistence service was
already shut down.");
emFactory.close();
}


google...@googlecode.com

unread,
Jan 21, 2013, 9:15:57 AM1/21/13
to google-g...@googlegroups.com

Comment #6 on issue 598 by terciofi...@gmail.com: Persist Extension:
PersistService.start() cannot be called multiple times
http://code.google.com/p/google-guice/issues/detail?id=598

Same here. I need to restart and when I call the second start it just throw
an exception. emFactory should be set null when stop.

google...@googlecode.com

unread,
Jun 4, 2013, 11:26:36 AM6/4/13
to google-g...@googlegroups.com

Comment #7 on issue 598 by guillaum...@gmail.com: Persist Extension:
PersistService.start() cannot be called multiple times
http://code.google.com/p/google-guice/issues/detail?id=598

Any chance this issues gets solved at some point? This would really be
helpful in the context of tests where (in-memory) databases needs to be
created and then dropped (which can easily be achieved by closing the EMF).

--
You received this message because this project is configured to send all
issue notifications to this address.
You may adjust your notification preferences at:
https://code.google.com/hosting/settings

google...@googlecode.com

unread,
Jul 16, 2013, 5:28:40 AM7/16/13
to google-g...@googlegroups.com

Comment #8 on issue 598 by xavier.d...@gmail.com: Persist Extension:
PersistService.start() cannot be called multiple times
http://code.google.com/p/google-guice/issues/detail?id=598

In the meantime, what I do is bind an interceptor around
PersistService.class which swallows IllegalStateExceptions...

google...@googlecode.com

unread,
Jul 16, 2013, 7:48:15 AM7/16/13
to google-g...@googlegroups.com

Comment #9 on issue 598 by terciofi...@gmail.com: Persist Extension:
PersistService.start() cannot be called multiple times
http://code.google.com/p/google-guice/issues/detail?id=598

@xavier, the problem is not the exception itself, but the fact that we
cannot re-start the PersistService. Sometimes I need to start, do same job,
stop and start again after some modifications to the configuration in
runtime.

Do you accept patches? Seriously, more than 2 years to set a variable to
null.

google...@googlecode.com

unread,
Dec 20, 2013, 9:28:38 AM12/20/13
to google-g...@googlegroups.com
Updates:
Labels: -Extension-Persist Component-Persist

Comment #10 on issue 598 by sberlin: Persist Extension:
PersistService.start() cannot be called multiple times
http://code.google.com/p/google-guice/issues/detail?id=598

(No comment was entered for this change.)

google...@googlecode.com

unread,
May 20, 2014, 11:59:39 PM5/20/14
to google-g...@googlegroups.com

Comment #11 on issue 598 by dha...@gmail.com: Persist Extension:
PersistService.start() cannot be called multiple times
http://code.google.com/p/google-guice/issues/detail?id=598

I don't think we should allow restarting a PersistService. Other options
are:
- instead you can create a new Injector/PersistService combination
- user a child-injector (or PrivateModule) to isolate different persist
services

We can add the isActive() method. However I am loathe to assume arbitrary
ordering of service starts. If you install the PersistFilter it should give
you a strong guarantee of having initialized the service when the filter is
ready to receive requests.

google...@googlecode.com

unread,
May 27, 2014, 10:18:16 AM5/27/14
to google-g...@googlegroups.com

Comment #12 on issue 598 by terciofi...@gmail.com: Persist Extension:
PersistService.start() cannot be called multiple times
http://code.google.com/p/google-guice/issues/detail?id=598

I just don't get the point not to allow restarting.

google...@googlecode.com

unread,
May 27, 2014, 3:00:32 PM5/27/14
to google-g...@googlegroups.com

Comment #13 on issue 598 by guillaum...@gmail.com: Persist Extension:
PersistService.start() cannot be called multiple times
http://code.google.com/p/google-guice/issues/detail?id=598

I don't get it either. In the context of unit tests, it is very useful to
be able to create an EMF pointing to an in-memory database which gets
created upon the service start and deleted when the service stops. Allowing
to restart, actually allows to execute several unit-tests.

google...@googlecode.com

unread,
May 27, 2014, 4:52:34 PM5/27/14
to google-g...@googlegroups.com

Comment #14 on issue 598 by dha...@gmail.com: Persist Extension:
PersistService.start() cannot be called multiple times
http://code.google.com/p/google-guice/issues/detail?id=598

It's pretty simple to just create a new injector for a new unit test isn't
it?

I don't think it's the right pattern to share the Injector + PersistService
across unit tests...

google...@googlecode.com

unread,
May 27, 2014, 5:15:13 PM5/27/14
to google-g...@googlegroups.com

Comment #15 on issue 598 by terciofi...@gmail.com: Persist Extension:
PersistService.start() cannot be called multiple times
http://code.google.com/p/google-guice/issues/detail?id=598

My situation is kind of different. I start the persistence service, get
some info from the database, re-configure the application and start the
service again. I cannot create a new injector, all the dependencies in my
application have already been binded.

google...@googlecode.com

unread,
Sep 14, 2014, 12:09:04 PM9/14/14
to google-g...@googlegroups.com

Comment #16 on issue 598 by ethan.hu...@web.de: Persist Extension:
PersistService.start() cannot be called multiple times
https://code.google.com/p/google-guice/issues/detail?id=598

Hi all,
I have the same problem.

I must have some code executed and using persistence on application startup.
The first request to my system then tries to configure the PersistFilter,
and this one starts the PersistService I already started on application
start.

How can I achieve this? Or avoid a new PersistService start?

Can someone paste a piece of code, to do this?
> #8 xavier.d...@gmail.com

> In the meantime, what I do is bind an interceptor around
> PersistService.class which >swallows IllegalStateExceptions...

kind regards
Patrick

google...@googlecode.com

unread,
Sep 15, 2014, 12:42:14 AM9/15/14
to google-g...@googlegroups.com

Comment #17 on issue 598 by michael....@gmail.com: Persist Extension:
PersistService.start() cannot be called multiple times
https://code.google.com/p/google-guice/issues/detail?id=598

I solved the problem by creating my own class extended
JpaPersistService with the overloaded method:
@Override
public synchronized void start() {
try {
super.start();
} catch (IllegalStateException e) {
; // no worries if it's already running.
}
}

I then added bindings for my class to the injector:

bind(PersistService.class).to(MyJpaPersistService.class);
bind(JpaPersistService.class).to(MyJpaPersistService.class);
bind(MyJpaPersistService.class).in(Singleton.class);

It sounds like Xavier did the equivalent using Guice's AOP features:
https://github.com/google/guice/wiki/AOP

Our application encounters the problem in a similar way as #15
describes: We attach to the database with one configuration to do
things like database migrations, and then reconfigure for normal use
with more limited permissions.

google...@googlecode.com

unread,
Sep 16, 2014, 2:51:03 PM9/16/14
to google-g...@googlegroups.com

Comment #18 on issue 598 by ethan.hu...@web.de: Persist Extension:
PersistService.start() cannot be called multiple times
https://code.google.com/p/google-guice/issues/detail?id=598

Hi,
overloading might work if I trick package visibility of JpaPersistService
by faking package structure com.google.inject.persist.jpa in my project to
be able to extend JpaPersistService, but JpaPersistModule also binds
JpaPersistService and guice complains about "A binding to
com.google.inject.persist.PersistService was already configured at
com.google.inject.persist.jpa.JpaPersistModule.configurePersistence(...)"

And overriding configureServlets() of JpaPersistModule() does not work,
because this class is final.

Any other ideas?

regards
Patrick

google...@googlecode.com

unread,
Sep 16, 2014, 2:52:43 PM9/16/14
to google-g...@googlegroups.com

Comment #19 on issue 598 by ethan.hu...@web.de: Persist Extension:
PersistService.start() cannot be called multiple times
https://code.google.com/p/google-guice/issues/detail?id=598

I mean...
"And overriding configurePersistence() of JpaPersistModule()..."

google...@googlecode.com

unread,
Sep 16, 2014, 5:44:21 PM9/16/14
to google-g...@googlegroups.com

Comment #20 on issue 598 by michael....@gmail.com: Persist Extension:
PersistService.start() cannot be called multiple times
https://code.google.com/p/google-guice/issues/detail?id=598

install(Modules.override(new
JpaPersistModule("yourjpaunitstring")).with(new
YourCustomizedPersistModule()));

where YourCustomizedPersistModule does the bindings I showed previously:
@Override
protected void configure() {
bindConstant().annotatedWith(Jpa.class).to("yourjpaunitstring");
bind(Properties.class).annotatedWith(Jpa.class).toInstance(new
Properties());
bind(PersistService.class).to(YourCustomizedJpaPersistService.class);
bind(JpaPersistService.class).to(YourCustomizedJpaPersistService.class);
bind(YourCustomizedJpaPersistService.class).in(Singleton.class);

google...@googlecode.com

unread,
Sep 18, 2014, 1:40:03 AM9/18/14
to google-g...@googlegroups.com

Comment #21 on issue 598 by ethan.hu...@web.de: Persist Extension:
PersistService.start() cannot be called multiple times
https://code.google.com/p/google-guice/issues/detail?id=598

Does the YourCustomizedPersistModule class just extends AbstractModule or
also PersistModule like the default JpaPersistModule?

google...@googlecode.com

unread,
Sep 18, 2014, 1:50:51 AM9/18/14
to google-g...@googlegroups.com

Comment #22 on issue 598 by michael....@gmail.com: Persist Extension:
PersistService.start() cannot be called multiple times
https://code.google.com/p/google-guice/issues/detail?id=598

Just AbstractModule. In the end it's the JpaPersistModule that gets
installed; it just gets some bindings overridden by
YourCustomizedPersistModule.
Reply all
Reply to author
Forward
0 new messages