Bug 997928 - package-info.java with @TypeDef annotation not processed
package-info.java with @TypeDef annotation not processed
Product: JBoss Enterprise Application Platform 6
Classification: JBoss
Component: JPA (Show other bugs)
Unspecified Unspecified
unspecified Severity unspecified
: ER4
: EAP 6.2.0
Assigned To: Scott Marlow
Zbyněk Roubalík
Russell Dickenson
Depends On:
  Show dependency treegraph
Reported: 2013-08-16 10:23 EDT by Martin Grotzke
Modified: 2013-12-16 10:45 EST (History)
4 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2013-12-15 11:55:49 EST
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)
Logs with TRACE logging for org.jboss.as.jpa enabled (28.88 KB, text/plain)
2013-09-03 16:02 EDT, Martin Grotzke
no flags Details

  None (edit)
Description Martin Grotzke 2013-08-16 10:23:46 EDT
(I have checked already in the forum if this is a bug: https://community.jboss.org/message/832099)

In EAP 6.1 a package-info.java with a hibernate @TypeDef annotation is not processed, when deploying the war jboss reports a
  "MappingException: Could not determine type ...".

This issue happens with EAP 6.1 (tested on Linux/Fedora, should not be relevant). In contrast, with AS 7.1.1.Final and current wildfly master it's working as expected (UserTypes registered via @TypeDef on package-info.java are used by hibernate).
I've modified the hibernate4 sample that allows to reproduce the issue:
(commit 9d0cd7d6 shows what's changed)
To reproduce the issue:
$ git clone git@github.com:magro/jboss-as-quickstart.git
$ cd jboss-as-quickstart/hibernate4
start your EAP 6.1 standalone
$ mvn clean package jboss-as:deploy
This fails with "org.hibernate.MappingException: Could not determine type for: org.jboss.as.quickstart.hibernate4.model.EmailAddress", log output (log output with TRACE level enabled for JPA is here: https://gist.github.com/magro/6250301/raw/6211afa2250b4fbf3102d83ebeddbbff9bd94fd3/jboss.log):

> 12:25:26,176 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-4) JBAS015876: Starting deployment of "jboss-as-hibernate4.war" (runtime-name: "jboss-as-hibernate4.war")
> 12:25:26,222 INFO  [org.jboss.as.jpa] (MSC service thread 1-14) JBAS011401: Read persistence.xml for primary
> 12:25:26,240 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-13) JBAS015877: Stopped deployment jboss-as-hibernate4.war (runtime-name: jboss-as-hibernate4.war) in 63ms
> 12:25:26,245 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-9) JBAS015876: Starting deployment of "jboss-as-hibernate4.war" (runtime-name: "jboss-as-hibernate4.war")
> 12:25:26,285 INFO  [org.jboss.as.jpa] (MSC service thread 1-5) JBAS011401: Read persistence.xml for primary
> 12:25:26,308 INFO  [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-6) JBAS010400: Bound data source [java:jboss/datasources/Hibernate4QuickstartDS]
> 12:25:26,319 INFO  [org.jboss.weld.deployer] (MSC service thread 1-10) JBAS016002: Processing weld deployment jboss-as-hibernate4.war
> 12:25:26,321 INFO  [org.jboss.as.ejb3.deployment.processors.EjbJndiBindingsDeploymentUnitProcessor] (MSC service thread 1-10) JNDI bindings for session bean named MemberRegistration in deployment unit deployment "jboss-as-hibernate4.war" are as follows:
>         java:global/jboss-as-hibernate4/MemberRegistration!org.jboss.as.quickstart.hibernate4.service.MemberRegistration
>         java:app/jboss-as-hibernate4/MemberRegistration!org.jboss.as.quickstart.hibernate4.service.MemberRegistration
>         java:module/MemberRegistration!org.jboss.as.quickstart.hibernate4.service.MemberRegistration
>         java:global/jboss-as-hibernate4/MemberRegistration
>         java:app/jboss-as-hibernate4/MemberRegistration
>         java:module/MemberRegistration
> 12:25:26,353 INFO  [org.jboss.weld.deployer] (MSC service thread 1-4) JBAS016005: Starting Services for CDI deployment: jboss-as-hibernate4.war
> 12:25:26,363 INFO  [org.jboss.as.jpa] (ServerService Thread Pool -- 11) JBAS011402: Starting Persistence Unit Service 'jboss-as-hibernate4.war#primary'
> 12:25:26,364 INFO  [org.hibernate.ejb.Ejb3Configuration] (ServerService Thread Pool -- 11) HHH000204: Processing PersistenceUnitInfo [
>         name: primary
>         ...]
> 12:25:26,365 INFO  [org.jboss.weld.deployer] (MSC service thread 1-6) JBAS016008: Starting weld service for deployment jboss-as-hibernate4.war
> 12:25:26,386 ERROR [org.jboss.msc.service.fail] (ServerService Thread Pool -- 11) MSC000001: Failed to start service jboss.persistenceunit."jboss-as-hibernate4.war#primary": org.jboss.msc.service.StartException in service jboss.persistenceunit."jboss-as-hibernate4.war#primary": javax.persistence.PersistenceException: [PersistenceUnit: primary] Unable to build EntityManagerFactory
>         at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1.run(PersistenceUnitServiceImpl.java:103)
>         at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_25]
>         at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_25]
>         at java.lang.Thread.run(Thread.java:724) [rt.jar:1.7.0_25]
>         at org.jboss.threads.JBossThread.run(JBossThread.java:122) [jboss-threads-2.1.0.Final-redhat-1.jar:2.1.0.Final-redhat-1]
> Caused by: javax.persistence.PersistenceException: [PersistenceUnit: primary] Unable to build EntityManagerFactory
>         at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:930)
>         at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:904)
>         at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:92)
>         at org.jboss.as.jpa.service.PersistenceUnitServiceImpl.createContainerEntityManagerFactory(PersistenceUnitServiceImpl.java:200)
>         at org.jboss.as.jpa.service.PersistenceUnitServiceImpl.access$600(PersistenceUnitServiceImpl.java:57)
>         at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1.run(PersistenceUnitServiceImpl.java:99)
>         ... 4 more
> Caused by: org.hibernate.MappingException: Could not determine type for: org.jboss.as.quickstart.hibernate4.model.EmailAddress, at table: MemberHibernate4Demo, for columns: [org.hibernate.mapping.Column(email)]
>         at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:314)
>         at org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:292)
>         at org.hibernate.mapping.Property.isValid(Property.java:239)
>         at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:469)
>         at org.hibernate.mapping.RootClass.validate(RootClass.java:270)
>         at org.hibernate.cfg.Configuration.validate(Configuration.java:1284)
>         at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1742)
>         at org.hibernate.ejb.EntityManagerFactoryImpl.<init>(EntityManagerFactoryImpl.java:94)
>         at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:920)
>         ... 9 more
> 12:25:26,500 ERROR [org.jboss.as.server] (management-handler-thread - 1) JBAS015860: Redeploy of deployment "jboss-as-hibernate4.war" was rolled back with the following failure message: 
> {"JBAS014671: Failed services" => {"jboss.persistenceunit.\"jboss-as-hibernate4.war#primary\"" => "org.jboss.msc.service.StartException in service jboss.persistenceunit.\"jboss-as-hibernate4.war#primary\": javax.persistence.PersistenceException: [PersistenceUnit: primary] Unable to build EntityManagerFactory
>     Caused by: javax.persistence.PersistenceException: [PersistenceUnit: primary] Unable to build EntityManagerFactory
>     Caused by: org.hibernate.MappingException: Could not determine type for: org.jboss.as.quickstart.hibernate4.model.EmailAddress, at table: MemberHibernate4Demo, for columns: [org.hibernate.mapping.Column(email)]"}}

This happens because the package-info.java with the @TypeDef (for EmailAddress UserType) is not processed.
During debugging I found that in HibernateAnnotationScanner.getPackagesInJar some class.getPackage() returns null, because the underlying classloader does not know the package of the class.
This is the related call stack copied from eclipse's Debug view:

> TempClassLoader(ConcurrentClassLoader).findLoadedPackage(String) line: 499
> TempClassLoader(ConcurrentClassLoader).getPackageByName(String) line: 477
> TempClassLoader(ConcurrentClassLoader).getPackage(String) line: 465
> Package.getPackage(Class<?>) line: 332
> Class<T>.getPackage() line: 717
> HibernateAnnotationScanner.getPackagesInJar(URL, Set<Class<Annotation>>) line: 182
> Ejb3Configuration.addScannedEntries(ScanningContext, List<String>, List<String>, List<NamedInputStream>, List<String>) line: 491
> Ejb3Configuration.scanForClasses(ScanningContext, List<String>, List<String>, List<NamedInputStream>) line: 866
> Ejb3Configuration.configure(PersistenceUnitInfo, Map) line: 605
> HibernatePersistence.createContainerEntityManagerFactory(PersistenceUnitInfo, Map) line: 91
The TempClassLoader asked to findLoadedPackage(String) contains a packages field (Map<String, Package>), which is plain empty.
I haven't debugged further why there are no packages defined in the classloader (should happen via definePackage), perhaps it's just the wrong classloader that's used.
Comment 1 Martin Grotzke 2013-09-03 11:28:07 EDT
Any feedback?
Comment 2 Brett Meyer 2013-09-03 13:27:51 EDT
Martin, can you enable TRACE logging for org.jboss.as.jpa (https://docs.jboss.org/author/display/AS72/JPA+Reference+Guide#JPAReferenceGuide-Troubleshooting) and also attach the server.log?  I want to first make sure it's not a classloader issue -- we recently had a few possibly related JPA issues.
Comment 3 Brett Meyer 2013-09-03 13:37:56 EDT
Actually, it looks like this may be https://bugzilla.redhat.com/show_bug.cgi?id=963298 and https://issues.jboss.org/browse/WFLY-17.  A similar issue came up caused by TempClassLoader being used before all transitive dependencies are available.
Comment 5 Martin Grotzke 2013-09-03 16:02:22 EDT
Created attachment 793344 [details]
Logs with TRACE logging for org.jboss.as.jpa enabled

Attached logs with TRACE enabled for org.jboss.as.jpa enabled, this is what I already referenced (https://gist.github.com/magro/6250301/raw/6211afa2250b4fbf3102d83ebeddbbff9bd94fd3/jboss.log)
Comment 6 Martin Grotzke 2013-09-03 16:28:49 EDT
Brett, thanx for having a look! I checked both issues, to me both don't look very similar, but I don't know much about jboss internals. And if classloader related things are fixed perhaps this one is resolved as well. AFAIU #963298 should be fixed in 6.1.1.ER4, can I download/clone this version somewhere to check if this issue is solved?
Comment 7 Scott Marlow 2013-09-03 19:09:46 EDT
The issues seem similar but are different.  I was able to recreate today (classWithAnnotation.getPackage() returns null which I need to check into).
Comment 10 Scott Marlow 2013-09-04 11:25:32 EDT
Looks like org.jboss.as.jpa.classloader.TempClassLoader needs to implement getPackage(String name) or getPackageByName(String name).
Comment 11 Scott Marlow 2013-09-04 11:44:39 EDT
Created upstream jira https://issues.jboss.org/browse/WFLY-2001 for this issue.
Comment 12 Jeffrey 2013-09-09 13:25:36 EDT
Just wanted to note that this problem also is a problem is you use name="xx" in the TypeDef annotation as well as with the defaultForType

Note You need to log in before you can comment on or make changes to this bug.