> - does it mean that all the annotated (say, with @Entity) classes will be added to the empty pu?
The empty pu is only used for weaving. It isn't used to create a proper EntityManagerFactory. I don't entirely know how the transformer works, but I assume it is smart enough to know that it's persistence unit is defined with <exclude-unlisted-classes>false so it will enhance anything with an @Entity annotation. Obviously this breaks down somewhat if you are defining anything in an orm.xml... but I think that is a solvable problem. I'm digressing here, but I think anytime you need to use an orm.xml file for a testcase, it'll need to be added to this 'empty' / weaving only pu.
> - the whole process will be repeated each time createEntityManagerFactory is called;
I don't follow. A transformer should only be registered on the premain called.
> - how do we ever create a regular pu (seem like never go past this nameless one)
I'm not entirely sure I follow this comment, but I'll give it a shot... currently there isn't any support for using a 'normal' persistence unit that is defined in a persistence.xml. It would be easy enough to add something like this if it was required though.
> -- I guess we could only use the new code if puName==null;
The only time this new 'dynamic persistence unit' support kicks in is if you pass a SEPersistenceUnitInfo in the properties map on a .createEntityManagerFactory call.
> - worse yet, if the class is already loaded dynamic weaving won't work (too late):
I think that would happen if you use a static variable static Dog myDog = new Dog("My"); that forces to class to load.
I don't think this is comment is entirely correct. When using the javaagent, the transformer gets loaded/registered prior to any test classes / Entities being loaded so that shouldn't be a problem.
Attached to this email is a working copy of what I'm proposing. Go ahead an unzip it into eclipselink.runtime\jpa and give it a run. You should be able to import it directly into Eclipse also. To run in Eclipse you'll need to set the db connection details / -javaagent as jvm args. Note that the TestInheritancePrePersist test is currently failing.