[hibernate-issues] [Hibernate-JIRA] Commented: (ANN-332) Using an @OneToMany/ManyToMany to hbm mapped class causes error.

Mufaddal (JIRA) noreply at atlassian.com
Wed Dec 13 15:50:04 EST 2006


    [ http://opensource.atlassian.com/projects/hibernate/browse/ANN-332?page=comments#action_25629 ] 

Mufaddal commented on ANN-332:
------------------------------

Seeing a similar problem here. Just upgraded to hibernate 3.2.1 GA

I have two classes like such:

@Entity
@Cache(usage=CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class Category implements TanEntity, Imageable
{
...
    @Id
    private String id;
    
    @Version
    private Long version = null;
....
....
    @CollectionOfElements
    @OneToMany(cascade = CascadeType.ALL)
    @MapKey(name = "name")
    @JoinColumn
    @Cascade(org.hibernate.annotations.CascadeType.DELETE_ORPHAN)
    private Map<String, CategoryAttribute> attributeValues = new HashMap<String, CategoryAttribute>();
 ....
....
}

@Entity
@Cache(usage=CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class CategoryAttribute implements TanEntity
{  
  @Id
  @GeneratedValue(generator = "system-uuid")
  @GenericGenerator(name = "system-uuid", strategy = "uuid")
  private String id;
  
  @Version
  private Long version;
  
  private String name;
	
  @CollectionOfElements	
  @org.hibernate.annotations.MapKey(columns={@Column(name="productCount")})
  @Column(name="productCount", nullable=false, columnDefinition="INTEGER UNSIGNED") 
  private Map<String, Integer> values = new HashMap<String, Integer>();
  
   ....
   ....
}	

Both classes are mapped in the hibernate.cfg.xml file like such:

....
....
  <mapping class="com.ac.tan.core.beans.CategoryAttribute"/>
  <mapping class="com.ac.tan.core.beans.Category"/>
....

When I deploy my web application, I see the following trace in my tomcat logs:

1534 ERROR org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/t] listenerStart [3696] - Exception sending context initialized event to listener instance of class com.ac.tan.web.TanContextListener
org.hibernate.AnnotationException: Use of @OneToMany or @ManyToMany targeting an unmapped class: com.ac.tan.core.beans.Category.attributeValues[com.ac.tan.core.beans.CategoryAttribute]
        at org.hibernate.cfg.annotations.CollectionBinder.bindManyToManySecondPass(CollectionBinder.java:1016)
        at org.hibernate.cfg.annotations.CollectionBinder.bindStarToManySecondPass(CollectionBinder.java:567)
        at org.hibernate.cfg.annotations.MapBinder$1.secondPass(MapBinder.java:80)
        at org.hibernate.cfg.CollectionSecondPass.doSecondPass(CollectionSecondPass.java:43)
        at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1127)
        at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:296)
        at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1283)
        at com.ac.tan.core.TanContext.configHibernate(TanContext.java:403)
        at com.ac.tan.core.TanContext.startup(TanContext.java:209)
        at com.ac.tan.web.TanWebApplication.startup(TanWebApplication.java:134)
        at com.ac.tan.web.TanContextListener.contextInitialized(TanContextListener.java:23)
        at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3692)
        at org.apache.catalina.core.StandardContext.start(StandardContext.java:4127)
        at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:759)
        at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:739)
        at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:524)
        at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:910)
        at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:873)
        at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:474)
        at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1118)
        at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:310)
        at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
        at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1020)
        at org.apache.catalina.core.StandardHost.start(StandardHost.java:718)
        at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1012)
        at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:442)
        at org.apache.catalina.core.StandardService.start(StandardService.java:450)
        at org.apache.catalina.core.StandardServer.start(StandardServer.java:680)
        at org.apache.catalina.startup.Catalina.start(Catalina.java:536)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:275)
        at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)

Any pointers?

> Using an @OneToMany/ManyToMany to hbm mapped class causes error.
> ----------------------------------------------------------------
>
>          Key: ANN-332
>          URL: http://opensource.atlassian.com/projects/hibernate/browse/ANN-332
>      Project: Hibernate Annotations
>         Type: Bug

>   Components: binder
>     Versions: 3.1beta8
>  Environment: hibernate 3.1
> hibernate-annotations 3.1-beta8
>     Reporter: Chris Rudd
>  Attachments: mappings.tar.gz
>
>
> Using an OneToMany/ManyToMany relationship to hbm mapped class from an annotated class causes error. If both classes are mapped the same way (annotated or hbm) this works fine. Also using a ManyToOne or OneToOne relationship works correctly.
> Stack Trace :
> org.hibernate.MappingException: Could not determine type for: mappings.HbmMapped, for columns: [org.hibernate.mapping.Column(elt)]
> 	at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:266)
> 	at org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:253)
> 	at org.hibernate.mapping.Collection.validate(Collection.java:262)
> 	at org.hibernate.cfg.Configuration.validate(Configuration.java:988)
> 	at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1169)
> 	at mappings.MappingTest.testOneToMany(MappingTest.java:113)
> 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> 	at java.lang.reflect.Method.invoke(Method.java:585)
> 	at org.testng.internal.MethodHelper.invokeMethod(MethodHelper.java:536)
> 	at org.testng.internal.Invoker.invokeMethod(Invoker.java:395)
> 	at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:672)
> 	at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:92)
> 	at org.testng.TestRunner.privateRun(TestRunner.java:624)
> 	at org.testng.TestRunner.run(TestRunner.java:515)
> 	at org.testng.SuiteRunner.privateRun(SuiteRunner.java:221)
> 	at org.testng.SuiteRunner.run(SuiteRunner.java:147)
> 	at org.testng.eclipse.runner.RemoteTestNG.run(RemoteTestNG.java:98)
> 	at org.testng.eclipse.runner.RemoteTestNG.main(RemoteTestNG.java:138)

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