Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version:
3.x
Mapping documents:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name = "com.jd.hibernate.associations.Users" table = "TEST_JD_USERS" discriminator-value="Users">
<id name = "id" column = "ID" type = "int">
<generator class = "increment"/>
</id>
<!-- following column need not be defined as property in pojo -->
<discriminator column = "Users_Type" type = "java.lang.String" />
<property name = "userType" type = "java.lang.String" column = "USERTYPE" />
<property name = "password" type = "java.lang.String" column = "PASSWORD" />
<property name = "firstName" type = "java.lang.String" column = "FIRSTNAME" />
<property name = "lastName" type = "java.lang.String" column = "LASTNAME" />
<property name = "email" type = "java.lang.String" column = "EMAIL" />
<property name = "homePhone" type = "java.lang.String" column = "HOMEPHONE" />
<property name = "workPhone" type = "java.lang.String" column = "WORKPHONE" />
</class>
<subclass name = "com.jd.hibernate.associations.PresentingUser"
extends ="com.jd.hibernate.associations.Users" discriminator-value="PresentingUser" >
<property name = "company" type = "java.lang.String" column = "COMPANY" />
<property name = "companyUrl" type = "java.lang.String" column = "COMPANYURL" />
<property name = "companyState" type = "java.lang.String" column = "COMPANYSTATE" />
<property name = "companyStreetAddress" type="java.lang.String" column="COSTREETADDR" />
<property name = "companyZipCode" type="int" column="COZIPCODE" />
</subclass>
<subclass name = "com.jd.hibernate.associations.ParticipatingUser"
extends ="com.jd.hibernate.associations.Users" discriminator-value="ParticipatingUser" >
<property name = "eventParticipatingIn" type="java.lang.String" column="EVENTPARTICIPATEIN" />
</subclass>
<subclass name = "com.jd.hibernate.associations.NormalUser"
extends ="com.jd.hibernate.associations.Users" discriminator-value="NormalUser" >
</subclass>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
session = sessionFactory.openSession();
tx = session.beginTransaction();
tx.begin();
ParticipatingUser pUser = new ParticipatingUser();
pUser.setEmail("navnith@asd.com");
pUser.setEventParticipatingIn("EventParticipating in");
pUser.setFirtName("asd");
pUser.setHomePhone(0303);
pUser.setLastName("M");
pUser.setPassword("asd");
pUser.setUserType("Super");
pUser.setWorkPhone(131311);
session.save(pUser);
tx.commit();
session.close();
Full stack trace of any exception that occurs:
Exception in thread "main" org.hibernate.PropertyNotFoundException: Could not find a getter for firstName in class com.jd.hibernate.associations.NormalUser
at org.hibernate.property.BasicPropertyAccessor.createGetter(BasicPropertyAccessor.java:282)
at org.hibernate.property.BasicPropertyAccessor.getGetter(BasicPropertyAccessor.java:275)
at org.hibernate.mapping.Property.getGetter(Property.java:272)
at org.hibernate.tuple.entity.PojoEntityTuplizer.buildPropertyGetter(PojoEntityTuplizer.java:247)
at org.hibernate.tuple.entity.AbstractEntityTuplizer.<init>(AbstractEntityTuplizer.java:125)
at org.hibernate.tuple.entity.PojoEntityTuplizer.<init>(PojoEntityTuplizer.java:55)
at org.hibernate.tuple.entity.EntityEntityModeToTuplizerMapping.<init>(EntityEntityModeToTuplizerMapping.java:56)
at org.hibernate.tuple.entity.EntityMetamodel.<init>(EntityMetamodel.java:295)
at org.hibernate.persister.entity.AbstractEntityPersister.<init>(AbstractEntityPersister.java:434)
at org.hibernate.persister.entity.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:109)
at org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:55)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:226)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1294)
at com.jd.hibernate.associations.TestUsers.main(TestUsers.java:14)
Name and version of the database you are using:
Ms Sql Server 2000
I am a Noob.I have RTFM.
I am trying to do a simple table per class hierachy association.
My previous sample worked. However in this one, I have one class which has no body or properties but just extends a parent class. I am not even calling this code. However this gives a problem.
I have a base class User. and sub classes as X,Y,Z.
Z does not have any body. I am calling setters on class Y. and during running... the above given is the problem. I would be grateful if some one could point out the wrong in the code ( or the approach ?)
thanks