user225928
user225928

Reputation: 75

PersistenceUnitInfo implementation in EclipseLink

EntityManagerFactory can be created without a persistence unit xml using

org.eclipse.persistence.jpa.PersistenceProvider {
 public EntityManagerFactory createContainerEntityManagerFactory(PersistenceUnitInfo info,
                                                                    java.util.Map properties)
    }

but what is the implementation class of javax.persistence.spi.PersistenceUnitInfo in eclipselink

Upvotes: 2

Views: 2061

Answers (3)

tomk
tomk

Reputation: 31

Java EE platform spec 6 says : the container is responsible for finding persistence.xml condensing the information into PersistenceUnitInfo and supplying that with a call to createContainerEntityManagerFactory.

Upvotes: 1

daizhuoxian
daizhuoxian

Reputation: 421

I am struggling on this problem too. I think that a PersistenceUnitInfo must be provided by the container(i.e. Application Server). It means that Eclipselink do not create one itself. If you are using Spring ORM, it uses a DefaultPersistenceUnitManager and call its obtainPersistenceUnitInfo(String unitName) method to get a instance of PersistenceUnitInfo. The unitName must be defined in persistence.xml. This means that you still needs an xml file.

By digging into the source code of Spring ORM, I found that Spring provides several implementations of PersistenceUnitInfo. In fact they are generally a Java Bean. You may be interested in SmartPersistenceInfo, MutablePersistenceInfo and SpringPersistenceUnitInfo. View them on Github.

EDIT:

I found the implementation of Eclipselink: It's SEPersistenceUnitInfo in org.eclipse.persistence.internal.jpa.deployment. Also found the method that reads every persistence unit in the configuration xml file.

    public static Set<SEPersistenceUnitInfo> getPersistenceUnits(ClassLoader loader, Map m, List<URL> jarFileUrls) {
    String descriptorPath = (String) m.get(PersistenceUnitProperties.ECLIPSELINK_PERSISTENCE_XML);
    if(descriptorPath == null) {
        descriptorPath = System.getProperty(PersistenceUnitProperties.ECLIPSELINK_PERSISTENCE_XML, PersistenceUnitProperties.ECLIPSELINK_PERSISTENCE_XML_DEFAULT);
    }
    Set<Archive> archives = findPersistenceArchives(loader, descriptorPath, jarFileUrls);
    Set<SEPersistenceUnitInfo> puInfos = new HashSet();
    try {
        for(Archive archive : archives) {
            List<SEPersistenceUnitInfo> puInfosFromArchive = getPersistenceUnits(archive, loader);
            puInfos.addAll(puInfosFromArchive);
        }
    } finally {
        for(Archive archive : archives) {
            archive.close();
        }
    }
    return puInfos;
}

Upvotes: 5

James
James

Reputation: 18379

PersistenceUnitInfo is defined by the Spec, refer to the JPA spec code or JavaDoc for its implementation.

http://www.eclipse.org/eclipselink/api/2.5/javax/persistence/spi/PersistenceUnitInfo.html

Upvotes: 0

Related Questions