-->
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.  [ 4 posts ] 
Author Message
 Post subject: PropertyNotFoundException
PostPosted: Wed Oct 15, 2003 9:34 am 
Newbie

Joined: Wed Oct 15, 2003 9:20 am
Posts: 12
Location: Qu
Hi,

I try to create a persistent class with 2 members: aLabID and aName. (The coding standard tell me to put a 'a' at the beggining of every member).

So, I have constructed the .hbm.xml like this:

Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
        "-//Hibernate/Hibernate Mapping DTD//EN"
        "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
  <class name="example.cLaboratory" table="lab">
    <id name="alabID" column="lab_id" type="string" length="20">
      <generator class="assigned"/>
    </id>
    <property name="aName" column="name" type="string" length="30"/>
  </class>
</hibernate-mapping>


I have used the CodeGenerator tool to create the java source file related to this hbm.(net.sf.hibernate.tool.hbm2java.CodeGenerator).

I have created a a TestApp to create a object in the database:

Code:
package example;

import net.sf.hibernate.Session;
import net.sf.hibernate.SessionFactory;
import net.sf.hibernate.cfg.Configuration;
import net.sf.hibernate.Hibernate;

import example.cLaboratory;


public class TestApp {
   
   public TestApp() {
      Session s = null;
      SessionFactory sf = null;
      Configuration cfg = new Configuration();
      
      try {
         cfg.addClass(example.cLaboratory.class);
         sf = cfg.buildSessionFactory();
         s = sf.openSession();
      }
      catch(Exception e) {
         e.printStackTrace();
         System.exit(1);
      }
      
      try {
         cLaboratory lab = new cLaboratory("lab1");
         
         s.save(lab);
         s.flush();
         s.connection().commit();
      }
      catch (Exception e) {
         e.printStackTrace();
      }
      finally {
         if(s != null) {
            try {
               s.close();
            } catch (Exception e) {
               e.printStackTrace();
            }
         }         
      }
   }

   static public void main(String args[]) {
      new TestApp();
   }
}

I have compiled the files. When I run the TestApp, I have the following message:

Code:
net.sf.hibernate.PropertyNotFoundException: Could not find a setter for property aLabID in class example.cLaboratory
    at net.sf.hibernate.util.ReflectHelper.getSetter(ReflectHelper.java:146)
    at net.sf.hibernate.persister.AbstractEntityPersister.<init>(AbstractEntityPersister.java:451)
............
    at example.TestApp.<init>(TestApp.java:20)
    at example.TestApp.main(TestApp.java:51)


I a change the aLabID for labID and aName for name, it work well.

Did somebody have a idea? Any suggestions?

That's sure that I can change the member names, but there's a lot of classes already existing that are used in the production environment, so I can't really do that.

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 15, 2003 9:39 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
The property name is the name of the get/set pair, NOT the name of the instance variable!

Or do you mean that your get/set pair is really named like getAName()/setAName() ? In that case use AName as the property name.

P.S. This is an absurd coding standard ;)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 15, 2003 10:01 am 
Senior
Senior

Joined: Tue Sep 23, 2003 8:18 am
Posts: 137
Location: Johannesburg, South Africa
I got this exception when a Hibernate mapping property was not defined in my object.

Check your cLaboratory class and make sure it has both of the GET and SET methods for that property.

Along with what Gavin said, in Java, all classes should start with a capital letter, while methods and variables start with small letters. Noticed that you have a class called "cLaboratory". This should rather be "CLaboratory", and an instance of it (an object), could be "cLaboratory".

This is an accepted Java coding standard, so much so, that many IDE's today will warn you about this.

-G


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 15, 2003 10:03 am 
Newbie

Joined: Wed Oct 15, 2003 9:20 am
Posts: 12
Location: Qu
Thanks for your answers.

(Note: The coding standard was already there when I was hired, so I need to live with that ;-). I agree that's not a good standard.)

The member in the class are prefixed with a 'a'. A member that indicate a name will be named 'aName'. the get/set in the class are 'mGetName', 'mSetName'. 'm' for method I think and 'a for attribute.


I have tried to change by hand the get/set generated from the CodeGenerator to getaLabID/setaLabID and getaName/setaName and it works now.

Thanks.


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