-2

I always get error java.sql.SQLSyntaxErrorException: ORA-00904: : invalid identifier and java.sql.SQLSyntaxErrorException: ORA-00942: table or view does not exist when creating table. This is some of my tables

package com.domibowo.salestracking.models;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import org.hibernate.annotations.GenericGenerator;

import javax.persistence.*;
import java.util.List;

@Entity
@Table(schema = "SALES_TRACKING", name="CUSTOMER")
public class Customer {

    @Id
    @GeneratedValue(generator = "seq", strategy= GenerationType.SEQUENCE)
    @SequenceGenerator(name="seq", sequenceName = "SEQ1")
    private Long id;
    @Column(name="citizen_id")
    private Long citizenId;
    @Column(name = "full_name")
    private String fullName;
    @Column(name = "address")
    private String address;
    @Column(name="city")
    private String city;

    @ManyToOne
    @JoinColumn(name="region_id")
    @JsonIgnoreProperties(value = {"salesList","customerList"})
    private Region region;

    @Transient
    private Long regionId;

    @OneToMany(mappedBy = "customer")
    private List<Details> details;

    public Customer() {
    }

    public Customer(Long id, Long citizenId, String fullName, String address, String city, Region region, Long regionId, List<Details> details) {
        this.id = id;
        this.citizenId = citizenId;
        this.fullName = fullName;
        this.address = address;
        this.city = city;
        this.region = region;
        this.regionId = regionId;
        this.details = details;
    }

    public Long getId() {
        return id;
    }

    public Long getCitizenId() {
        return citizenId;
    }

    public void setCitizenId(Long citizen_id) {
        this.citizenId = citizen_id;
    }

    public String getFullName() {
        return fullName;
    }

    public void setFullName(String full_name) {
        this.fullName = full_name;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getCity() {
        return city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    public Region getRegion() {
        return region;
    }

    public void setRegion(Region region) {
        this.region = region;
    }

    public List<Details> getDetails() {
        return details;
    }

    public void setDetails(List<Details> details) {
        this.details = details;
    }

    public Long getRegionId() {
        return regionId;
    }

    public void setRegionId(Long regionId) {
        this.regionId = regionId;
    }
}

The product table and the rest are able to create without any problem.

But this,

package com.domibowo.salestracking.models;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import org.hibernate.annotations.GenericGenerator;

import javax.persistence.*;
import java.time.LocalDate;

@Entity
@Table(schema = "SALES_TRACKING",name="HISTORY")
public class History {

    @Id
    @GeneratedValue(generator = "seq", strategy= GenerationType.SEQUENCE)
    @SequenceGenerator(name="seq", sequenceName = "SEQ1")
    private Long id;

    @ManyToOne
    @JoinColumn(name = "sales_id")
    @JsonIgnoreProperties(value = {"region"})
    private Sales sales;

    @OneToOne
    @JoinColumn(name = "details_id")
    @JsonIgnoreProperties(value = {"history"})
    private Details details;

    @Column(name = "date")
    @JsonFormat(pattern = "dd/MM/yyyy")
    private LocalDate date;

    @Column(name = "total")
    private Double total;

    @Transient
    private Long detailsId;

    @Transient
    private Long salesId;

    public History() {
    }

    public History(Long id, Sales sales, Long salesId, Details details, LocalDate date, Double total, Long detailsId) {
        this.id = id;
        this.sales = sales;
        this.details = details;
        this.date = date;
        this.total = total;
        this.detailsId = detailsId;
        this.salesId = salesId;
    }

    public Long getDetailsId() {
        return detailsId;
    }

    public void setDetailsId(Long detailsId) {
        this.detailsId = detailsId;
    }

    public Long getId() {
        return id;
    }

    public Sales getSales() {
        return sales;
    }

    public void setSales(Sales sales) {
        this.sales = sales;
    }

    public Details getDetails() {
        return details;
    }

    public void setDetails(Details details) {
        this.details = details;
    }

    public Double getTotal() {
        return total;
    }

    public void setTotal(Double total) {
        this.total = total;
    }

    public LocalDate getDate() {
        return date;
    }

    public void setDate(LocalDate date) {
        this.date = date;
    }

    public Long getSalesId() {
        return salesId;
    }

    public void setSalesId(Long salesId) {
        this.salesId = salesId;
    }
}

I always get ORA-00904 and ORA-00942 errors when creating History table even if the generator id used is the same as others. Any help much appreciated!!

1 Answer 1

1

Even while using Hibernate JPA you must not forget you use the Oracle database and you must avoid using reserved words as columns names.

So please review all columns names, particularly this one

 @Column(name = "date")

The error ORA-00904 invalid identifier point in this direction. DATE is a reserved word and can't be used as column name.

The second one (ORA-00942 table or view does not exist) is a followup message caused by the fact that the table can't be created.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.