[hibernate-issues] [Hibernate-JIRA] Created: (EJB-401) @OneToOne or @ManyToOne references an unknown entity when maven-surefire-test runs without -DforkMode=none property

Farrukh Najmi (JIRA) noreply at atlassian.com
Fri Nov 14 09:30:15 EST 2008


@OneToOne or @ManyToOne references an unknown entity when maven-surefire-test runs without -DforkMode=none property
-------------------------------------------------------------------------------------------------------------------

                 Key: EJB-401
                 URL: http://opensource.atlassian.com/projects/hibernate/browse/EJB-401
             Project: Hibernate Entity Manager
          Issue Type: Bug
          Components: EntityManager
    Affects Versions: 3.3.2.GA
            Reporter: Farrukh Najmi
            Priority: Critical



I have an entity class called Referer that references another entity class called Referenced as follows:

//The class that has a reference
@Entity(name = "acme.Referer")
@Table(name = "REFERER")
@Inheritance(strategy = InheritanceType.JOINED)
public class DeliveryInfoType extends RefererBase {
    @ManyToOne(targetEntity = acme.Referenced.class, cascade = {
        CascadeType.ALL
    })
    @JoinColumn(name = "REFERER_REFERENCED_ID")
    protected acme.Referenced referenced;

    ...
}

//The class that is being referenced
@Entity(name = "acme.Referenced")
@Table(name = "REFERENCED")
@Inheritance(strategy = InheritanceType.JOINED)
public class EndpointReferenceType
...
}

The abstract base class for Referer is a mapped superclass called RefererBase as follows:

@MappedSuperclass
public abstract class ExtensibleObjectType {
...
}

When I run a junit test via maven-surefire-plugin while specifying the -DforkMode=none property then the test succeeds.
When I run a junit test via maven-surefire-plugin without specifying the -DforkMode=none property then the test fails when creating the EntityManagerFactory as follows.

Caused by: javax.persistence.PersistenceException: [PersistenceUnit: my-persistence-unit] Unable to configure EntityManagerFactory
        at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:265)
        at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:125)
        at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:83)
        at acme.SomeClass.createEntityManagerFactory(SomeClass.java:278)
        at acme.SomeClass.setUp(SomeClass.java:233)
        at acme.SomeClass.<init>(SomeClass.java:57)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
        at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:100)
        ... 57 more
Caused by: org.hibernate.AnnotationException: @OneToOne or @ManyToOne on acme.Referer.referenced references an unknown entity: acme.Referenced
        at org.hibernate.cfg.ToOneFkSecondPass.doSecondPass(ToOneFkSecondPass.java:81)
        at org.hibernate.cfg.AnnotationConfiguration.processFkSecondPassInOrder(AnnotationConfiguration.java:499)
        at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:304)
        at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1121)
        at org.hibernate.ejb.Ejb3Configuration.buildMappings(Ejb3Configuration.java:1225)
        at org.hibernate.ejb.EventListenerConfigurator.configure(EventListenerConfigurator.java:159)
        at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:854)
        at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:191)
        at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:253)
        ... 67 more

maven-surefire-plugin defines its forkMode property as follows at <http://maven.apache.org/plugins/maven-surefire-plugin/test-mojo.html>:

forkMode  	String  	Option to specify the forking mode. Can be "never", "once" or "always". "none" and "pertest" are also accepted for backwards compatibility. Default value is once.

I am baffled as to why hiberante EntityManager is behaving working when forkMode is set to "none" but fails when forkMode is set to default of "once".
It seems like a classloader related issue. Here are the hibernate related jars in my webapp:

org.hibernate:hibernate-search:jar:3.0.1.GA
org.hibernate:hibernate:jar:3.2.6.ga
org.hibernate:hibernate-entitymanager:jar:3.3.2.GA
org.hibernate:hibernate-commons-annotations:jar:3.0.0.ga
org.hibernate:ejb3-persistence:jar:1.0.1.GA
org.hibernate:hibernate-annotations:jar:3.3.1.GA

This issue may possibly be related to following issue:
<http://opensource.atlassian.com/projects/hibernate/browse/EJB-199>

-- 
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