Java ORA-00904: : Hibernate Dependent 对象程序的标识符无效问题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20968840/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ORA-00904: : invalid identifier Issue with Hibernate Dependent objects program
提问by Chaitanya
I am working on a simple hibernate dependent objectsprogram using Oracle
as my database.
我正在开发一个简单的休眠相关对象程序,Oracle
用作我的数据库。
Here are my POJO classes:
这是我的 POJO 课程:
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
人.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.
我已经在我的文件中设置了hbm2ddl.auto
属性,所以当我执行我的程序时会创建表。update
hibernate.cfg.xml
Here is my simple program that tries to save an instance of Person object:
这是我尝试保存 Person 对象实例的简单程序:
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
15:20:45,376 错误架构更新:235 - HHH000388:不成功:创建表 person1(pid varchar2(255)不为空,生日日期,初始字符(1),第一个 varchar2(255),最后一个 varchar2(255),主键( pid))
15:20:45,376 错误 SchemaUpdate:236 - ORA-00904 :: 标识符无效
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?
我尝试在Person
班级和Name
班级中更改我的属性名称,但我仍然面临这个问题。请让我知道我在哪里做错了?
采纳答案by M21B8
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.
无效标识符并不意味着您的主键是错误的,这意味着列标识符之一无效。我相信您的问题是“初始”列,它是 Oracle 中的保留字。
http://docs.oracle.com/cd/B19306_01/server.102/b14200/ap_keywd.htm
http://docs.oracle.com/cd/B19306_01/server.102/b14200/ap_keywd.htm