ORA-00904::Hibernate依赖对象程序的无效标识符问题 [英] ORA-00904: : invalid identifier Issue with Hibernate Dependent objects program

查看:615
本文介绍了ORA-00904::Hibernate依赖对象程序的无效标识符问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究一个简单的 hibernate依赖对象程序使用 Oracle 作为我的数据库。



这里是我的POJO类:





  public class Person {
private java.util.Date birthday;
私人姓名;
私人字符串键;
... getters& setters ...
}

名称

  public class Name {
char initial;
字符串优先;
最后一个字符串;
... getters& setters ...
}

Hibernate映射文件:

person.hbm.xml

 < hibernate-mapping> 
< class name =Persontable =person1>
< id name =Keycolumn =pidtype =string>
< generator class =uuid/>
< / id>
< property name =birthdaytype =date/>
< component name =Nameclass =Name> <! - 类属性可选 - >
< property name =initial/>
< property name =first/>
< property name =last/>
< / component>
< / class>
< / hibernate-mapping>

我已经设置了 hbm2ddl.auto 属性作为 update 在我的 hibernate.cfg.xml 文件中,所以当我执行我的程序时会创建表。



以下是我试图保存Person对象实例的简单程序:

  public class Program {
public static void main(String [] args){
Session session = HibernateUtil.getSessionFactory()。getCurrentSession();
session.beginTransaction();

名称=新名称();
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();




$ b现在当我执行这个程序时,创建表本身时出错:


15:20:45,376错误SchemaUpdate:235 - HHH000388:不成功:创建
表person1 (pid varchar2(255)不为空,生日日期,初始
char(1),第一个varchar2(255),最后一个varchar2(255),主键(pid))

15:20:45,376 ERROR SchemaUpdate:236 - ORA-00904::invalid identifier

我的属性在 Person class以及 Name class中,但仍然面临着这个问题。请让我知道我在做什么错误?

解决方案

无效的标识符并不意味着您的主键是错误的,其中一个列标识符无效。我相信你的问题是'初始'列,这是Oracle的一个保留字。



http://docs.oracle.com/cd/B19306_01/server.102/b14200/ap_keywd.htm


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

这篇关于ORA-00904::Hibernate依赖对象程序的无效标识符问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆