[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-4864) "Cannot read files twice on NativeScanner" exception when using multiple persistence.xml

Vincent MATHON (JIRA) noreply at atlassian.com
Tue Apr 6 11:01:02 EDT 2010


    [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-4864?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=36171#action_36171 ] 

Vincent MATHON commented on HHH-4864:
-------------------------------------

I use the same code as Bouiaw pointed out. To deal with hibernate 3.5.0-Final I simply override org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager#obtainPersistenceUnitInfo as follow:

@Override
public PersistenceUnitInfo obtainPersistenceUnitInfo(String persistenceUnitName) {
	PersistenceUnitInfo persistenceUnitInfo = super.obtainPersistenceUnitInfo(persistenceUnitName);
persistenceUnitInfo.getJarFileUrls().remove(persistenceUnitInfo.getPersistenceUnitRootUrl());
return persistenceUnitInfo;

	}


Under the cover, I ask spring to process all META-INF/persistence-spring.xml files (I have renamed persistence.xml files to avoid interferences with JPA engines) in the classpath using the same code as the one at http://ancientprogramming.blogspot.com/2007/05/multiple-persistencexml-files-and.html . I end with a merged persistence unit whose root url is the one of the last processed persistence-spring.xml file. The JarFileUrls collection of this merged persistence unit also contains the root URL and hibernate 3.5.x does not allow to process a jar twice as previous versions did. Withdrawing the root URL from the JarFileUrls when possible solves the issue.



> "Cannot read files twice on NativeScanner" exception when using multiple persistence.xml
> ----------------------------------------------------------------------------------------
>
>                 Key: HHH-4864
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-4864
>             Project: Hibernate Core
>          Issue Type: Bug
>          Components: core
>    Affects Versions: 3.5.0-Beta-3
>            Reporter: Bouiaw
>
> When subclassing DefaultPersistenceUnitManager as described in http://ancientprogramming.blogspot.com/2007/05/multiple-persistencexml-files-and.html in order to have my entities in different jars, Hibernate 3.5-Beta3 throw the following exception (it worked with previous version of Hibernate) :
> java.lang.RuntimeException: error trying to scan <jar-file>: file:/Users/bouiaw/resthub/resthub-core/target/classes/
> 	at org.hibernate.ejb.Ejb3Configuration.scanForClasses(Ejb3Configuration.java:700)
> 	at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:465)
> 	at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:165)
> 	at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:225)
> 	at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:288)
> 	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1457)
> 	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1397)
> 	... 51 more
> Caused by: org.hibernate.AssertionFailure: Cannot read files twice on NativeScanner
> 	at org.hibernate.ejb.packaging.NativeScanner.getFilesInJar(NativeScanner.java:168)
> 	at org.hibernate.ejb.Ejb3Configuration.addScannedEntries(Ejb3Configuration.java:393)
> 	at org.hibernate.ejb.Ejb3Configuration.scanForClasses(Ejb3Configuration.java:697)
> 	... 57 more

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the hibernate-issues mailing list