"ERROR: ORA-00911: invalid character " for create tables by Hibernate JPA

"ERROR: ORA-00911: invalid character " for create tables by Hibernate JPA

我想用 Hibernate JPA 创建两个表。 我使用 Oracle 11gJDBC 6 & 7(因为我不确定哪个适合 11g :))。

我的图书馆:hibernate-release-4.2.0.Final & hibernate-jpa-2.0-api-1.0.1 & Tomcat-8 lib & JDK 1.8.0-172

我创建了两个实体,但是当我 运行 程序时,没有创建表并出现此错误:

Nov 12, 2018 10:15:35 AM org.hibernate.tool.hbm2ddl.SchemaExport perform
ERROR: HHH000389: Unsuccessful: create table "PICTURE" ("PID" `NUMBER` not null, " CAPTION " `LONG `, " LIKES_COUNTER " ` NUMBER `, " PIC_ADRESS " `     NVARCHAR2(50) ` not null,  FK_USERS `NUMBER`, primary key ("PID"))
Nov 12, 2018 10:15:35 AM org.hibernate.tool.hbm2ddl.SchemaExport perform
ERROR: ORA-00911: invalid character

Nov 12, 2018 10:15:35 AM org.hibernate.tool.hbm2ddl.SchemaExport perform
ERROR: HHH000389: Unsuccessful: create table "USERS" ("UID" `NUMBER` not null, " EMAIL " ` NVARCHAR2(40)` not null, " USER_PASSWORD " ` NVARCHAR2(32)` not null, " USER_SEX " ` NVARCHAR2(20)`, " UPICADD " ` NVARCHAR2(50)`, " USERNAME " ` NVARCHAR2(30)` not null, primary key ("UID"))
Nov 12, 2018 10:15:35 AM org.hibernate.tool.hbm2ddl.SchemaExport perform
ERROR: ORA-00911: invalid character

我运行这些查询直接在SQLPLUS上进行测试。表已正确创建。即使当我使用 <property name="hibernate.hbm2ddl.auto" value="create-drop"/> 时,我直接创建的表也被删除但没有重建。

我的实体:

@Entity (name = "person")
@Table(name = "USERS")
@EntityListeners(value = PersonManager.class)
public class Person implements Serializable
{
    @Id 
    @Column(name="UID" ,columnDefinition = "NUMBER" )
    @SequenceGenerator(name = "mySeq" , sequenceName = "DB_MYSEQ")
    @GeneratedValue(strategy=GenerationType.AUTO ,generator="mySeq")
    private long uId;

//--------define relation------

    @OneToMany(cascade = CascadeType.ALL , fetch = FetchType.EAGER)
    @JoinColumn(name = " FK_USERS" )
    private List<Pictures> picturesList;

    @Basic
    @Column (name = " USERNAME " , columnDefinition = " NVARCHAR2(30)" , nullable = false )
    private String username ;

    @Basic
    @Column (name = " USER_PASSWORD " , columnDefinition = " NVARCHAR2(32)" , nullable = false )
    private String  password ;

    @Basic
    @Column (name = " EMAIL " , columnDefinition = " NVARCHAR2(40)" , nullable = false)
    private String email;

    @Basic // user picture for profile
    @Column (name = " UPICADD " , columnDefinition = " NVARCHAR2(50)" )
    private String userPic;

    @Basic
    @Column (name = " USER_SEX " , columnDefinition = " NVARCHAR2(20)")
    private String sex ;


    public Person(String username, String password, String email ,String sex, String userPic ) {
       this.picturesList = picturesList;
       this.sex = sex;
       this.userPic = userPic;
       this.email = email;
       this.password = password;
       this.username = username;
    }

   //--------------------------------------------------------

    public void setUsername(String username) {
       this.username = username;
    }

    public void setPassword(String password) {
       this.password = password;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public void setUserPic(String userPic) {
        this.userPic = userPic;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    public void setuId(long uId) {this.uId = uId;}
    public void setPicturesList(List<Pictures> picturesList) {
        this.picturesList = picturesList;
    }


//--------------------------------------------------------

    public String getUsername() {
       return username;
   }

    public String getPassword() {
       return password;
    }

    public String getUserPic() {
        return userPic;
    }

    public String getEmail() {
        return email;
    }

     public String getUser_Sex() {
        return sex;
   }
    public long getuId() {return uId;}

     public List<Pictures> getPicturesList() {
        return picturesList;
    }
}

 @Entity(name = "picture")
 @Table(name = "PICTURE")

public class Pictures implements Serializable
{
@Id // create id and fill auto by sequence in database
@Column(name="PID" ,columnDefinition = "NUMBER" )
@SequenceGenerator(name = "mySeq2" , sequenceName = "DB_MYSEQ2")
@GeneratedValue(strategy=GenerationType.AUTO ,generator="mySeq2")
private long pId;


@Basic
@Column (name = "PICADRESS" , columnDefinition = "NVARCHAR2(50)" , nullable = false)
private String  picAdress ;

@Basic
@Column (name = "CAPTION" , columnDefinition = "LONG")
private String caption;

@Basic 
@Column (name = "LIKE_COUNTER" , columnDefinition = "NUMBER")
private int likes;

//--------------------------------------------------------
public Pictures(){}

public Pictures( String picAdress, String caption, int likes) {
    this.picAdress = picAdress;
    this.caption = caption;
    this.likes = likes;
}
//--------------------------------------------------------

public void setPid(long pid) {
    this.pId = pid;
}

public void setLikes(int likes) {
    this.likes = likes;
}

public void setPicAdress(String picAdress) {
    this.picAdress = picAdress;
}

public void setCaption(String caption) {
    this.caption = caption;
}

//--------------------------------------------------------

public int getLikes() {
    return likes;
}

public String getCaption() {
    return caption;
}

public String getPicAdress() {
    return picAdress;
}

public long getPid() {
    return pId;
}
}

和persistence.xml:

<persistence-unit name="MyConnection" transaction-type="RESOURCE_LOCAL">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <properties>
        <property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect"/>
        <property name="hibernate.connection.driver_class" value="oracle.jdbc.driver.OracleDriver"/>
        <property name="hibernate.connection.username" value="midas"/>
        <property name="hibernate.connection.password" value="midas123"/>
        <property name="hibernate.connection.url" value="jdbc:oracle:thin:@localhost:1521:orcl"/>
        <property name="hibernate.hbm2ddl.auto" value="create"/>
        <property name="show_sql" value="true"></property>
        <property name="hibernate.globally_quoted_identifiers" value="true"/>
    </properties>
</persistence-unit>

我该如何解决?

我终于发现问题了。 这个 属性 <property name="hibernate.globally_quoted_identifiers" value="true"/> 在 persistence.xml 中,为任何 data_type 添加单引号而不是名称列!

我删除了它并解决了问题。 :)