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.