I have try to developed a inheritance with hibernate.
I have this error:
Code:
Initial SessionFactory creation failed.org.hibernate.PropertyNotFoundException: Could not find a getter for id in class com.dungino.databasefilm.Teacher
Exception in thread "main" java.lang.ExceptionInInitializerError
at com.dungino.databasefilm.util.HibernateUtil.<clinit>(HibernateUtil.java:15)
at main.HibernateLanch.listFilm(HibernateLanch.java:55)
at main.HibernateLanch.main(HibernateLanch.java:27)
Caused by: org.hibernate.PropertyNotFoundException: Could not find a getter for id in class com.dungino.databasefilm.Teacher
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:250)
at org.hibernate.tuple.PojoEntityTuplizer.buildPropertyGetter(PojoEntityTuplizer.java:255)
at org.hibernate.tuple.AbstractEntityTuplizer.<init>(AbstractEntityTuplizer.java:102)
at org.hibernate.tuple.PojoEntityTuplizer.<init>(PojoEntityTuplizer.java:55)
at org.hibernate.tuple.TuplizerLookup.create(TuplizerLookup.java:64)
at org.hibernate.tuple.EntityMetamodel.<init>(EntityMetamodel.java:257)
at org.hibernate.persister.entity.AbstractEntityPersister.<init>(AbstractEntityPersister.java:412)
at org.hibernate.persister.entity.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:108)
at org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:55)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:215)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1164)
at com.dungino.databasefilm.util.HibernateUtil.<clinit>(HibernateUtil.java:12)
... 2 more
It's the first example of this link:
http://vinaytechs.blogspot.com/2010/01/inheritance-using-hibernate.htmlI have create the table:
Code:
-- phpMyAdmin SQL Dump
-- version 3.4.3.1
-- http://www.phpmyadmin.net
--
-- Host: 127.0.0.1
-- Generato il: Feb 15, 2012 alle 21:57
-- Versione del server: 5.5.13
-- Versione PHP: 5.3.6
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
--
-- Database: `databasefilm`
--
-- --------------------------------------------------------
--
-- Struttura della tabella `person`
--
CREATE TABLE IF NOT EXISTS `person` (
`id` tinyint(4) NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL,
`person_type` varchar(255) NOT NULL,
`branch` varchar(255) DEFAULT NULL,
`department` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ;
--
-- Dump dei dati per la tabella `person`
--
INSERT INTO `person` (`id`, `name`, `person_type`, `branch`, `department`) VALUES
(1, 'Tom', 'Student', 'EC', NULL),
(2, 'Ross', 'Student', 'CS', NULL),
(3, 'Stephen', 'Teacher', NULL, 'Electronics');
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
Pojo file
Person.java
package com.dungino.databasefilm;
// Generated 14-feb-2012 22.21.53 by Hibernate Tools 3.4.0.CR1
/**
* Person generated by hbm2java
*/
public class Person implements java.io.Serializable {
private int id;
private String name;
private String personType;
public Person() {
}
public Person(String name, String personType) {
this.name = name;
this.personType = personType;
}
public int getId() {
return this.id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
public String getPersonType() {
return this.personType;
}
public void setPersonType(String personType) {
this.personType = personType;
}
}
Person.hbm.xml
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 14-feb-2012 22.13.32 by Hibernate Tools 3.4.0.CR1 -->
<hibernate-mapping>
<class name="com.dungino.databasefilm.Person" table="person">
<id name="id" type="int">
<column name="id" />
<generator class="assigned" />
</id>
<discriminator column="person_type" type="java.lang.String"/>
<property name="name" column="name" type="java.lang.String"/>
</class>
</hibernate-mapping>
Student.java
Code:
package com.dungino.databasefilm;
// Generated 14-feb-2012 22.21.53 by Hibernate Tools 3.4.0.CR1
public class Student extends Person implements java.io.Serializable {
private String branch;
public Student() {
}
public Student(String branch) {
this.branch = branch;
}
public String getBranch() {
return this.branch;
}
public void setBranch(String branch) {
this.branch = branch;
}
}
Student.hbm.xml
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 14-feb-2012 22.13.32 by Hibernate Tools 3.4.0.CR1 -->
<hibernate-mapping>
<subclass name="com.dungino.databasefilm.Student" extends="com.dungino.databasefilm.Person" discriminator-value="Student">
<property name="branch" column="branch" type="java.lang.String"/>
</subclass>
</hibernate-mapping>
Teacher.java
Code:
package com.dungino.databasefilm;
// Generated 14-feb-2012 22.21.53 by Hibernate Tools 3.4.0.CR1
public class Teacher implements java.io.Serializable {
private String department;
public Teacher() {
}
public Teacher(
String department) {
this.department = department;
}
public String getDepartment() {
return this.department;
}
public void setDepartment(String department) {
this.department = department;
}
}
Teacher.hbm.xml
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 14-feb-2012 22.13.32 by Hibernate Tools 3.4.0.CR1 -->
<hibernate-mapping>
<subclass name="com.dungino.databasefilm.Teacher" extends="com.dungino.databasefilm.Person" discriminator-value="Teacher">
<property name="department" column="department" type="java.lang.String"/>
</subclass>
</hibernate-mapping>
Help me !!!!