-->
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.  [ 3 posts ] 
Author Message
 Post subject: PropertyNotFoundException with @ManyToOne
PostPosted: Sun Apr 06, 2008 11:25 am 
Newbie

Joined: Sun Apr 06, 2008 10:58 am
Posts: 4
Location: UK
With the following two classes I am getting the exception:
PropertyNotFoundException: field [club_id] not found on com.bill.googlemaps.domain.Location

I am sure it is a newbie problem but this newbie is stuck.
Any thoughts greatly appreciated.

Code:

Caused by: org.hibernate.PropertyNotFoundException: field [club_id] not found on com.bill.googlemaps.domain.Location
   at org.hibernate.property.DirectPropertyAccessor.getField(DirectPropertyAccessor.java:122)
   at org.hibernate.property.DirectPropertyAccessor.getField(DirectPropertyAccessor.java:114)
   at org.hibernate.property.DirectPropertyAccessor.getGetter(DirectPropertyAccessor.java:137)
   at org.hibernate.util.ReflectHelper.getter(ReflectHelper.java:83)
   at org.hibernate.util.ReflectHelper.reflectedPropertyClass(ReflectHelper.java:71)
   at org.hibernate.mapping.SimpleValue.setTypeUsingReflection(SimpleValue.java:279)
   at org.hibernate.cfg.HbmBinder.createProperty(HbmBinder.java:2171)
   at org.hibernate.cfg.HbmBinder.createClassProperties(HbmBinder.java:2148)
   at org.hibernate.cfg.HbmBinder.createClassProperties(HbmBinder.java:2038)
   at org.hibernate.cfg.HbmBinder.bindRootPersistentClassCommonValues(HbmBinder.java:359)
   at org.hibernate.cfg.HbmBinder.bindRootClass(HbmBinder.java:273)
   at org.hibernate.cfg.HbmBinder.bindRoot(HbmBinder.java:144)
   at org.hibernate.cfg.Configuration.add(Configuration.java:675)
   at org.hibernate.cfg.AnnotationConfiguration.processArtifactsOfType(AnnotationConfiguration.java:483)
   at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:277)
   at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1121)
   at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:674)
   at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:211)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1288)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1257)
   ... 62 more


My Location class:

Code:
@Entity
@Table(name="locations")
public class Location {

   public Location() {
      super();
   }

   @Id
   @Column(name="id")
   private int id;

   @ManyToOne()
   @JoinColumn(name = "club_id", nullable = false)
   private Club club;


   public int getId() {
      return id;
   }

   public void setId(int id) {
      this.id = id;
   }

   public Club getClub() {
      return club;
   }

   public void setClub(Club club) {
      this.club = club;
   }
}


My Club class:
Code:

@Entity
@Table(name="clubs")
public class Club {
   
   public Club() {
      super();
   }

   @Id
   @Column(name="id")
   private int id;
   
   @OneToMany(mappedBy = "club")
   private List<Location> locations;


   public int getId() {
      return id;
   }

   public void setId(int id) {
      this.id = id;
   }


   public List<Location> getLocations() {
      return locations;
   }

   public void setLocations(List<Location> locations) {
      this.locations = locations;
   }
}


Top
 Profile  
 
 Post subject: try using the Java field name and not the column name
PostPosted: Sun Apr 06, 2008 11:32 am 
Newbie

Joined: Sun Apr 06, 2008 6:38 am
Posts: 4
When writing HQL queries, you should refer to Java field/property names and not the underlying SQL column names


Top
 Profile  
 
 Post subject: I'm a plonker
PostPosted: Sun Apr 06, 2008 11:57 am 
Newbie

Joined: Sun Apr 06, 2008 10:58 am
Posts: 4
Location: UK
Told you it was a newbie problem.

The above code is all unchanged.
My context.xml file was still referring to old style hbm.xml files for the beans instead of the hibernate3/spring 2.5 style.

Sorry


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.