I notice there's no "multiModule" test in the source tree for the 3.0RC I
have, so here's my quick stab at it:
1. Create an Annotation for each of your persistence units (say
DbOnePU.java, DbTwoPU.java).
2. Define both "DbOne" and "DbTwo" persistence units in persistence.xml.
3. Create DbOneManager & DbTwoManager (DAO or whatever that provides db
access methods).
4. Create DbOneInitializer & DbTwoInitializer (PersistService
start/stop).
5. For each persistence unit, create a PrivateModule following this
pattern:
public class DbOneModule extends PrivateModule {
protected void configure() {
JpaPersistModule jpm = new JpaPersistModule("DbOne");
jpm.properties(new Properties()); // some kinda bug without
this
jmp.addFinder(DbOneFinders.class); // an interface with any @Finder
methods.
install(jmp);
bind(DbOneManager.class).annotatedWith(DbOnePU.class).to(DbOneManager.class);
expose(DbOneManager.class).annotatedWith(DbOnePU.class);
bind(DbOneInitializer.class).annotatedWith(DbOnePU.class).to(DbOneInitializer.class);
expose(DbOneInitializer.class).annotatedWith(DbOnePU.class);
}
}
Injector creation, at least:
injector = Guice.createInjector(new DbOneModule(), new DbTwoModule());
Injection usage would be:
@Inject @DbOnePU DbOneManager dbOneMgr;
@Inject @DbOnePU DbOneInitializer dbOneInit;
@Inject @DbTwoPU DbTwoManager dbTwoMgr;
@Inject @DbTwoPU DbTwoInitializer dbTwoInit;
Caveat:
With Hibernate 3.5, at least, both of my persistence units seem to find *all
* of my Entities. Should be able to isolate Entities to one persistence
unit or the other, but no quick answer there. Cheers!
--
You received this message because you are subscribed to the Google Groups
"google-guice" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-guice?hl=en.