I am working on a simple hibernate dependent objects program using Oracle
as my database.
Here are my POJO classes:
Person
public class Person {
private java.util.Date birthday;
private Name name;
private String key;
... getters & setters ...
}
Name
public class Name {
char initial;
String first;
String last;
... getters & setters ...
}
Hibernate mapping file:
person.hbm.xml
<hibernate-mapping>
<class name="Person" table="person1">
<id name="Key" column="pid" type="string">
<generator class="uuid" />
</id>
<property name="birthday" type="date" />
<component name="Name" class="Name"> <!-- class attribute optional -->
<property name="initial" />
<property name="first" />
<property name="last" />
</component>
</class>
</hibernate-mapping>
I have set the hbm2ddl.auto
property as update
in my hibernate.cfg.xml
file so tables are created when I execute my program.
Here is my simple program that tries to save an instance of Person object:
public class Program {
public static void main(String[] args) {
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
Name name = new Name();
name.setFirst("First");
name.setLast("First");
name.setInitial('I');
Person person = new Person();
person.setBirthday(new Date());
person.setName(name);
session.save(person);
session.getTransaction().commit();
HibernateUtil.getSessionFactory().close();
}
}
Now when I am executing this program, I am getting error while creation of table itself:
15:20:45,376 ERROR SchemaUpdate:235 - HHH000388: Unsuccessful: create table person1 (pid varchar2(255) not null, birthday date, initial char(1), first varchar2(255), last varchar2(255), primary key (pid))
15:20:45,376 ERROR SchemaUpdate:236 - ORA-00904: : invalid identifier
I tried changing names of my properties in Person
class as well as Name
class but still I am facing this issue. Please let me know where I am doing mistake?
Invalid identifier doesn't mean your primary key is wrong, it means that one of the column identifiers is invalid. I believe your problem is the 'initial' column, which is a reserved word in Oracle.
http://docs.oracle.com/cd/B19306_01/server.102/b14200/ap_keywd.htm
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With