2017-05-05 6 views
0

나는 PostgreSQL을에 테이블을 다음 있습니다 : JPA 도구와JPA 도구로이 Java Entities가 생성 되었습니까?

CREATE TABLE public.company_subscripcion ( 
    id_suscription int4 NOT NULL, 
    status   char(1) NOT NULL, 
    id_company  int4 NOT NULL, 
    PRIMARY KEY(id_suscription,id_company) 
) 
GO 
ALTER TABLE public.company_subscripcion 
    ADD CONSTRAINT company_subscripcion_id_suscription_fkey 
    FOREIGN KEY(id_suscription) 
    REFERENCES public.subscription(id_suscription) 
    ON DELETE NO ACTION 
    ON UPDATE NO ACTION 
GO 
ALTER TABLE public.company_subscripcion 
    ADD CONSTRAINT company_subscripcion_id_company_fkey 
    FOREIGN KEY(id_company) 
    REFERENCES public.company(id_company) 
    ON DELETE NO ACTION 
    ON UPDATE NO ACTION 
GO 


CREATE TABLE public.company ( 
    id_company  int4 NOT NULL, 
    id_corporation int4 NULL, 
    tin    varchar(20) NOT NULL, 
    short_name  varchar(20) NOT NULL, 
    name   varchar(100) NOT NULL, 
    commercial_name varchar(100) NOT NULL, 
    address   varchar(200) NOT NULL, 
    phone_number varchar(20) NULL, 
    logo_url  varchar(500) NULL, 
    created_by  int4 NOT NULL, 
    created   timestamp NOT NULL, 
    updated_by  int4 NULL, 
    last_update  timestamp NULL, 
    s3_bucket  varchar(20) NULL, 
    s3_access  varchar(20) NULL, 
    s3_secret  varchar(20) NULL, 
    sunat_username varchar(30) NULL, 
    sunat_password varchar(64) NULL, 
    others   text NULL, 
    PRIMARY KEY(id_company) 
) 

CREATE TABLE public.subscription ( 
    id_suscription  int4 NOT NULL, 
    automatic_renewal char(1) NOT NULL, 
    amount    numeric(10,2) NOT NULL, 
    status    char(1) NOT NULL, 
    start_date   date NULL, 
    expiration_date  date NULL, 
    id_user    int4 NULL, 
    id_plan    int4 NOT NULL, 
    created_by   int4 NOT NULL, 
    created    timestamp NOT NULL, 
    updated_by   int4 NULL, 
    last_update   timestamp NULL, 
    PRIMARY KEY(id_suscription) 
) 

나는이 엔티티를 생성했습니다

CompanySubscripcionPK.java

CompanySubscripcion.java

@Entity 
@Table(name="company_subscripcion") 
@NamedQuery(name="CompanySubscripcion.findAll", query="SELECT c FROM CompanySubscripcion c") 
public class CompanySubscripcion implements Serializable { 
    private static final long serialVersionUID = 1L; 
    @EmbeddedId 
    private CompanySubscripcionPK id; 
    private String status; 
    private Company company; 
    private Subscription subscription; 

    public CompanySubscripcion() { 
    } 

    public CompanySubscripcionPK getId() { 
     return this.id; 
    } 

    public void setId(CompanySubscripcionPK id) { 
     this.id = id; 
    } 


    @Column(nullable=false, length=1) 
    public String getStatus() { 
     return this.status; 
    } 

    public void setStatus(String status) { 
     this.status = status; 
    } 


    //uni-directional many-to-one association to Company 
    @ManyToOne 
    @JoinColumn(name="id_company", nullable=false, insertable=false, updatable=false) 
    public Company getCompany() { 
     return this.company; 
    } 

    public void setCompany(Company company) { 
     this.company = company; 
    } 


    //uni-directional many-to-one association to Subscription 
    @ManyToOne 
    @JoinColumn(name="id_suscription", nullable=false, insertable=false, updatable=false) 
    public Subscription getSubscription() { 
     return this.subscription; 
    } 

    public void setSubscription(Subscription subscription) { 
     this.subscription = subscription; 
    } 

} 

@Embeddable public class CompanySubscripcionPK implements Serializable { //default serial version id, required for serializable classes. private static final long serialVersionUID = 1L; private Integer idSuscription; private Integer idCompany; public CompanySubscripcionPK() { } @Column(name="id_suscription", insertable=false, updatable=false, unique=true, nullable=false) public Integer getIdSuscription() { return this.idSuscription; } public void setIdSuscription(Integer idSuscription) { this.idSuscription = idSuscription; } @Column(name="id_company", insertable=false, updatable=false, unique=true, nullable=false) public Integer getIdCompany() { return this.idCompany; } public void setIdCompany(Integer idCompany) { this.idCompany = idCompany; } public boolean equals(Object other) { if (this == other) { return true; } if (!(other instanceof CompanySubscripcionPK)) { return false; } CompanySubscripcionPK castOther = (CompanySubscripcionPK)other; return this.idSuscription.equals(castOther.idSuscription) && this.idCompany.equals(castOther.idCompany); } public int hashCode() { final int prime = 31; int hash = 17; hash = hash * prime + this.idSuscription.hashCode(); hash = hash * prime + this.idCompany.hashCode(); return hash; } } 
내가 company_subscripcion 테이블의 데이터를 읽기 위해 (내가는 EclipseLink를 사용하고 있습니다) ReadAllQuery 방법을 소비 할 때, 나는이 오류를 얻을 수 있기 때문에 6,

나는이 의심을 가지고 도움을

[EL Finest]: query: 2017-05-05 16:29:52.328--UnitOfWork(1108818591)--Thread(Thread[http-nio-8081-exec-8,5,main])--Execute query ReadAllQuery(referenceClass=CompanySubscripcion sql="SELECT STATUS, IDCOMPANY, IDSUSCRIPTION, COMPANY_id_company, SUBSCRIPTION_id_suscription FROM company_subscripcion") 
[EL Finest]: connection: 2017-05-05 16:29:52.328--ServerSession(2070565177)--Connection(641062437)--Thread(Thread[http-nio-8081-exec-8,5,main])--Connection acquired from connection pool [default]. 
[EL Fine]: sql: 2017-05-05 16:29:52.328--ServerSession(2070565177)--Connection(641062437)--Thread(Thread[http-nio-8081-exec-8,5,main])--SELECT STATUS, IDCOMPANY, IDSUSCRIPTION, COMPANY_id_company, SUBSCRIPTION_id_suscription FROM company_subscripcion 
[EL Fine]: sql: 2017-05-05 16:29:52.331--ServerSession(2070565177)--Thread(Thread[http-nio-8081-exec-8,5,main])--SELECT 1 
[EL Finest]: connection: 2017-05-05 16:29:52.333--ServerSession(2070565177)--Connection(641062437)--Thread(Thread[http-nio-8081-exec-8,5,main])--Connection released to connection pool [default]. 
[EL Warning]: 2017-05-05 16:29:52.333--UnitOfWork(1108818591)--Thread(Thread[http-nio-8081-exec-8,5,main])--Local Exception Stack: 
Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.5.0.v20130507-3faac2b): org.eclipse.persistence.exceptions.DatabaseException 
Internal Exception: org.postgresql.util.PSQLException: ERROR: no existe la columna «idcompany» 
    Hint: Perhaps you meant to reference the column "company_subscripcion.id_company". 
    Position: 16 
Error Code: 0 
Call: SELECT STATUS, IDCOMPANY, IDSUSCRIPTION, COMPANY_id_company, SUBSCRIPTION_id_suscription FROM company_subscripcion 
Query: ReadAllQuery(referenceClass=CompanySubscripcion sql="SELECT STATUS, IDCOMPANY, IDSUSCRIPTION, COMPANY_id_company, SUBSCRIPTION_id_suscription FROM company_subscripcion") 
    at org.eclipse.persistence.exceptions.DatabaseException.sqlException(DatabaseException.java:340) 
    at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.basicExecuteCall(DatabaseAccessor.java:679) 
    at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeCall(DatabaseAccessor.java:558) 
    at org.eclipse.persistence.internal.sessions.AbstractSession.basicExecuteCall(AbstractSession.java:1995) 
    at org.eclipse.persistence.sessions.server.ServerSession.executeCall(ServerSession.java:570) 

감사 나 :

업데이트 1

엔티티를 다시 생성했으며 이제는 작동합니다. 이 새로운 자격은 이전과 다릅니다 :

내 문제가 해결되었습니다. 감사.

답변

0

오류가 한쪽 전에 혼동 될 수는 그 열 idcompany

ERROR: no existe la columna «idcompany»

을 찾아 다른 측면에서 문제가 열 id_company

Hint: Perhaps you meant to reference the column "company_subscripcion.id_company"

와 것을 말한다 수 없다고

문제는 우리가 보여주는 코드가 데이터베이스의 id_company 열을 가리키고 그 열이 존재하지 않는다는 것입니다.

@Column(name="id_company" 

데이터베이스를 다시 확인하십시오.

Un abrazo!

+0

그러나 id_company 열이 존재합니다 ... JPA 도구로 자동 생성 된 엔티티가 맞는지 알 수 있습니다. –

+0

자동 생성 도구가 작동해야합니다. "개인 회사 회사"를 삭제할 수 있습니까? 그게 문제인지를 알아내는 getter와 setter 메서드입니까? –

+0

나는 뭔가 유선의 통지를했습니다 쿼리가 생성됩니다 : SELECT STATUS, IDCOMPANY, IDSUSCRIPTION, COMPANY_id_company, SUBSCRIPTION_id_suscription FROM company_subscripcion –