-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 15 posts ] 
Author Message
 Post subject: MappingException Could not determine type for java.util.Set
PostPosted: Fri Jun 15, 2007 12:32 pm 
Newbie

Joined: Tue Sep 12, 2006 6:06 pm
Posts: 15
I'm converting my Hibernate persistence layer to use annotations, but when I deploy the app I get the following error:

Code:
org.hibernate.MappingException: Could not determine type for: java.util.Set, for columns: [org.hibernate.mapping.Column(users)]
   at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:266)
   at org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:253)
   at org.hibernate.mapping.Property.isValid(Property.java:185)
   at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:440)
   at org.hibernate.mapping.RootClass.validate(RootClass.java:192)
   at org.hibernate.cfg.Configuration.validate(Configuration.java:1102)
   at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1287)
   at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:915)
   at org.springframework.orm.hibernate3.LocalSessionFactoryBean.newSessionFactory(LocalSessionFactoryBean.java:825)
   at org.springframework.orm.hibernate3.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:751)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1091)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:396)
   at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:233)
   at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:145)
   at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:186)
   at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:106)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1046)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:857)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:378)
   at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:233)
   at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:145)
   at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:186)
   at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:106)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1046)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:857)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:378)
   at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:233)
   at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:145)
   at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:186)
   at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:106)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1046)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:857)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:378)
   at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:233)
   at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:145)
   at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:186)
   at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:106)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1046)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:857)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:378)
   at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:233)
   at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:145)
   at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeansOfType(DefaultListableBeanFactory.java:211)
   at org.springframework.context.support.AbstractApplicationContext.getBeansOfType(AbstractApplicationContext.java:596)
   at org.springframework.context.support.AbstractApplicationContext.registerListeners(AbstractApplicationContext.java:478)
   at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:310)
   at org.springframework.web.context.support.AbstractRefreshableWebApplicationContext.refresh(AbstractRefreshableWebApplicationContext.java:139)
   at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:246)
   at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:184)
   at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:49)
   at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3729)
   at org.apache.catalina.core.StandardContext.start(StandardContext.java:4187)
   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.deployWAR(HostConfig.java:809)
   at org.apache.catalina.startup.HostConfig.deployWARs(HostConfig.java:698)
   at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:472)
   at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1122)
   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:1021)
   at org.apache.catalina.core.StandardHost.start(StandardHost.java:718)
   at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1013)
   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:709)
   at org.apache.catalina.startup.Catalina.start(Catalina.java:551)
   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:294)
   at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:432)


The error doesn't tell me exactly where the problem is, but I gather that it's most likely associated with one of several many-to-many relationships to the User class. Here is one of those getUser() methods with the associated annotation:

Code:
   @ManyToMany(fetch=FetchType.EAGER)
    @JoinTable(name="reservation_user", joinColumns = {
        @JoinColumn(name="reservation_key", nullable=false, updatable=false) }, inverseJoinColumns = {
        @JoinColumn(name="user_key", nullable=false, updatable=false) })
    @Cascade( {CascadeType.SAVE_UPDATE} )
    public Set<User> getUsers() {
      if (users == null){
         users = new HashSet<User>();
      }
      return users;
   }


This annotation was generated by hbm2java. I'm very new to annotations, but can anyone more experienced see anything wrong? Am I looking in the right place?

There were several posts on this error which noted that annotations should not be at both the field and getter level. Mine are all at the getter level, so that isn't the problem.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 15, 2007 5:40 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Seems like Annoation does not see @ManyToMany did you put @Id on a getter or on a field?

PS: Jeezzz 40 elements in the stacktrace for a DI...

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 15, 2007 5:48 pm 
Newbie

Joined: Tue Sep 12, 2006 6:06 pm
Posts: 15
It's on the getter. Here's what I have:

@Id @GeneratedValue
@Column(name="key_value", nullable=false)
public Long getKey() {
return key;
}

The key_value column is generated by MySql.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 15, 2007 5:51 pm 
Newbie

Joined: Tue Sep 12, 2006 6:06 pm
Posts: 15
Can you elaborate on the stacktrace comment?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 18, 2007 10:23 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Hum I can't understand the problem then. either what you deploy is not what you describe or the error is from another Entity deployed at the same time.

Code:
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1091)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:396)
   at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:233)
   at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:145)
   at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:186)
   at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:106)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1046)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:857)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:378)
   at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:233)
   at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:145)
   at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:186)
   at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:106)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1046)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:857)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:378)
   at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:233)
   at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:145)
   at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:186)
   at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:106)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1046)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:857)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:378)
   at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:233)
   at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:145)
   at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:186)
   at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:106)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1046)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:857)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:378)
   at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:233)
   at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:145)
   at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeansOfType(DefaultListableBeanFactory.java:211)


I was impressed by the stacktrace size

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 18, 2007 6:11 pm 
Newbie

Joined: Tue Sep 12, 2006 6:06 pm
Posts: 15
That's entirely possible since more than one entity has such a relationship to user, and the error message is not helpful in pinpointing it more accurately. I'm going to trash the hbm2java generated annotations and start over using the examples from the hibernate annotations download as a guide.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 19, 2007 2:56 pm 
Newbie

Joined: Tue Sep 12, 2006 6:06 pm
Posts: 15
Still no progress on this problem. I have two "users" relationships in persistent classes. Here they are:

Reservation

Code:
   @OneToMany(fetch=FetchType.EAGER)
    @JoinTable(name="reservation_user",
       joinColumns = {@JoinColumn(name="reservation_key") },
       inverseJoinColumns = {@JoinColumn(name="user_key") })
    public Set<User> getUsers() {
      if (users == null){
         users = new HashSet<User>();
      }
      return users;
   }


UserGroup
Code:
   @OneToMany(fetch=FetchType.EAGER)
    @JoinTable(name="user_group_user",
       joinColumns = {@JoinColumn(name="group_key") },
       inverseJoinColumns = {@JoinColumn(name="user_key") })
    public Set<User> getUsers() {
      if (users == null){
         users = new HashSet<User>();
      }
      return users;
   }


Here are the relevant portions of the User class:
Code:
@Entity
@Table(name="user")
public class User implements Serializable, ImageGetter, ImageSetter {
...
}



The error message:
org.hibernate.MappingException: Could not determine type for: java.util.Set, for columns: [org.hibernate.mapping.Column(users)]

... can only be referring to one of these two locations. Reservation has a one-to-many relationship to both User and UserGroup.

I've followed every rabbit trail I can think of, and I'm at a loss for what to do next. What am I missing?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 19, 2007 7:00 pm 
Newbie

Joined: Tue Sep 12, 2006 6:06 pm
Posts: 15
This completely incomprehensible. I commented out the annotations for both getUsers() methods in an effort to narrow down which of them is causing the problem, and the error still shows up!

Can this be a configuration problem? I have the following for each of my persistent domain classes in hibernate.cfg.xml.

<mapping class="com.silversky.scheduler.domain.User"/>

Is Hibernate sensitive to the order that these entities are mapped? When I moved the user mapping above to the top of the list, I got a different error. I don't know yet whether the error I mentioned previously is gone or merely masked by the current error, which is:

org.hibernate.MappingException: Repeated column in mapping for entity: com.silversky.scheduler.domain.SmsContactMethod column: type (should be mapped with insert="false" update="false")


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 20, 2007 2:49 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
no Hibernate is not sensitive to the ordering (at least when there is no error)
Try an reduce your mapping until you find the culprit.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 20, 2007 5:10 pm 
Newbie

Joined: Tue Sep 12, 2006 6:06 pm
Posts: 15
I've pared my mappings down to a handful of entities that have no references to any others and discovered something interesting. Any methods that start with "get" or "is" generate errors unless I mark them as @Transient, whether or not they actually refer to a property of the object. The Hibernate Annotations documentation contains the following statement:

Quote:
Every non static non transient property (field or method) of an entity bean is considered persistent, unless you annotate it as @Transient. Not having an annotation for your property is equivalent to the appropriate @Basic annotation.


Is this configurable? I have all of my persistent properties annotated with @Column, so I don't see why I need to otherwise mark these methods @Transient. What's the difference between @Basic and @Column?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 20, 2007 8:17 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
No it's not configurable, and you'd better of comply because that's the JPA standard :)
@Basic is a logic annotation, @Column is a physical detail

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 21, 2007 12:21 pm 
Newbie

Joined: Tue Sep 12, 2006 6:06 pm
Posts: 15
Understood. It's just a bit different than I expected. I thought that the conversion to annotations would be a lot less painful than it has turned out.


Top
 Profile  
 
 Post subject: Could not determine type for: java.util.Set, for columns:
PostPosted: Wed Feb 13, 2008 12:04 pm 
Newbie

Joined: Thu Mar 29, 2007 7:36 am
Posts: 9
Location: Romania
Hi Guys!

I have the same problem but in other context.

I have modified the templates, and run the hbmtemplate from maven, to generate classes with annotations.

The generated classes will compile, but when running the app (with jetty) I have the
applicationContext-hibernate.xml]: Invocation of init method failed; nested exception is org.hibernate.MappingException: Could not determine type for: java.util.Set, for columns: [org.hibernate.mapping.Column(my2ClasssForBodyid)]
error.

The generated class looks like
Code:
public class MyLocalizedClass implements java.io.Serializable, InterfaceWithoutLocalization{
private Set<My2LocalizedClass> my2LocalizedClassForBodyid = new HashSet<My2LocalizedClass>(0);

@OneToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY, mappedBy="aLocalizedTableForeignKey")
    public Set<My2LocalizedClass> getMy2LocalizedClasssForBodyid() {
        return my2LocalizedClassForBodyid;
    }
...
//added with template START
     public Set<? extends My2Interface> getMy2ClasssForBodyid() { //this method name appears in error as a column name
         return this.getMy2LocalizedClasssForBodyid();
     }
// added with template END

//the My2LocalizedClass implements My2Interface
}


I putted in the applicationContext-hibernate.xml the entry
<value>fully.qualified.nameof.My2Interface</value>
but no change.


So, my first question is, can I use the <? extends X> syntax or no,
the second is, why gives the error
Could not determine type for: java.util.Set, for columns: [org.hibernate.mapping.Column(my2ClasssForBodyid)], I have no column named my2ClasssForBodyid... it is just a function (getter) name.


Any idea?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 05, 2008 6:18 am 
Newbie

Joined: Tue Feb 26, 2008 8:31 am
Posts: 1
Hi all

I had the same problem right now. And I experimented with all kind of annotations. Finally I found out, that I had my annotations for several properties sometimes on the declaration and sometimes on the getter. And because of that, hibernate couldn't find the @OneToMany annotation


Top
 Profile  
 
 Post subject: RE: Could not determine type for: java.util.Set, for columns
PostPosted: Thu Mar 06, 2008 11:14 am 
Newbie

Joined: Thu Mar 29, 2007 7:36 am
Posts: 9
Location: Romania
Hi again!
For everybody interested, the answer is the following:

In ManyToOne releated methods, You can use an interface as a return type, but it is must(I putted there, but I don`t know if it is mandatory or not) to put the annotation:
Code:
@ManyToOne(targetEntity = TheConcreteClassWhichIsReturned.class)

So, for ex.

I have the Classes A, and B both implementing Interface I.

The I has the following method:
Code:
public Set<? extends I> getEntityByMyField();


For example in this case You can write/generate without problem (As a "ManyToOne method"):
Code:
// In A class:
@ManyToOne(fetch = FetchType.LAZY, targetEntity = A.class)
@JoinColumn(name = "MyField", nullable = false, insertable = false, updatable = false)
public A getEntityByMyField(){
//...
}

// In B class:
@ManyToOne(fetch = FetchType.LAZY, targetEntity = B.class)
@JoinColumn(name = "MyField", nullable = false, insertable = false, updatable = false)
public B getEntityByMyField(){
//...
}


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 15 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.