🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: pl.comp.lang.java
Article #153097

Problem z relacjami w derby

#153097
From: greg
Date: Tue, 01 Nov 2011 17:34
119 lines
5108 bytes
Witam
Nie jestem programistą java tylko pasjonuje mnie programowanie i uczę się
programować w tym języku. Stworzyłem już dwa programy z wykorzystaniem
języka java i bazy danych derby ale do tej pory nie używałem relacji  
OneToOne, OneToMany, ManyToOne w klasie komunikacji z
bazią danych, tworzyłem tabele w których zam określałem klucze obce i  
główne ale relacje
obsługiwałem z wykorzystaniem javy.

Teraz postanowiłem zająć stworzyć kolejny projekt korzystając z obsługi  
relacji w bazie danych. Do tego celu wykorzystuje OneToOne oraz OneToMany.  
Program się uruchamia, choć nie zawsze, ale nie mogę w programie dodać  
żadnych danych zastanawiam się czy dobrze stworzyłem klasy komunikujące  
się z bazą danych Derby.

Zamieszczam kod klas usuwając pola tekstowe i pola z wartościami  
liczbowych aby ułatwić czytanie kodu

@Entity
@Inheritance(strategy = InheritanceType.JOINED)
@DiscriminatorColumn(name = "TYPE")
@Table(name = "DBKOLEINOWANIE", catalog = "", schema = "APP")
public class dbKoleinowanie implements Serializable {
     private static final long serialVersionUID = 1L;
     @Id
     @GeneratedValue(strategy = GenerationType.AUTO)
     @Column(name = "ID")
     private Long id;
     ...
     @OneToMany(cascade=CascadeType.ALL, mappedBy = "dbKoleinowanie",  
targetEntity=dbKoleinowaniePozycje.class)
     @JoinColumn(name = "KOLEINOWANIEPOZYCJE")//, nullable=false)
     @PrimaryKeyJoinColumn
     private List<dbKoleinowaniePozycje> dbKoleinowaniePoz;// = null;
     @OneToOne(targetEntity=dbRecepty.class)
     @JoinColumn(name = "RECEPTY")
     private dbRecepty recepty;
     ...
     public Long getId() {
         return id;
     }
     public void setId(Long id) {
         this.id = id;
     }
     public List<dbKoleinowaniePozycje> getDbKoleinowaniePoz() {
         return dbKoleinowaniePoz;
     }
     public void setDbKoleinowaniePoz(List<dbKoleinowaniePozycje>  
dbKoleinowaniePoz) {
         this.setDbKoleinowaniePoz(dbKoleinowaniePoz);
     }
     public dbRecepty getRecepty() {
         return recepty;
     }
     public void setRecepty(dbRecepty recepty) {
         this.recepty = recepty;
     }
     ...
}

@Entity
@Table(name = "DBKOLEINOWANIEPOZYCJE", catalog = "", schema = "APP")
public class dbKoleinowaniePozycje implements Serializable {
     private static long serialVersionUID = 1L;

     @Id
     @GeneratedValue(strategy = GenerationType.AUTO)
     @Column(name = "ID")
     private Long id;
     @ManyToOne(optional=false,targetEntity=dbKoleinowanie.class)
     @JoinColumn(name = "KOLEINOWANIE_ID")//, referencedColumnName =  
"KOLEINOWANIEPOZYCJE")
     private dbKoleinowanie dbKoleinowanie;
     ...
     public Long getId() {
         return id;
     }
     public void setId(Long id) {
         this.id = id;
     }
     public dbKoleinowanie getDbKoleinowanie() {
         return dbKoleinowanie;
     }
     public void setDbKoleinowanie(dbKoleinowanie dbKoleinowanie) {
         this.dbKoleinowanie = dbKoleinowanie;
     }

}
Program się uruchamia albo dostaje takie komunikaty o błędach


Komunikat 1
java.lang.IllegalArgumentException: An exception occurred while creating a
query in EntityManager:
Exception Description: Error compiling the query [select object(o) from
dbKoleinowanie as o]. Unknown entity type [dbKoleinowanie].

Komunikat 2
Exception [EclipseLink-30005] (Eclipse Persistence Services -
2.0.1.v20100213-r6600):
org.eclipse.persistence.exceptions.PersistenceUnitLoadingException
Exception Description: An exception was thrown while searching for
persistence archives with ClassLoader:
sun.misc.Launcher$AppClassLoader@1cde100
Internal Exception: javax.persistence.PersistenceException: Exception
[EclipseLink-28018] (Eclipse Persistence Services -
2.0.1.v20100213-r6600):
org.eclipse.persistence.exceptions.EntityManagerSetupException
Exception Description: Predeployment of PersistenceUnit [badaniaDrogowePU]
failed.
Internal Exception: Exception [EclipseLink-7250] (Eclipse Persistence
Services - 2.0.1.v20100213-r6600):
org.eclipse.persistence.exceptions.ValidationException
Exception Description: [class tabelebazy.dbKoleinowanie] uses a non-entity
[class tabelebazy.dbKoleinowaniePozycje] as target entity in the
relationship attribute [field dbKoleinowaniePoz].

-- 
Grzegorz
Technical Details
Message-ID: <op.v3923fjrtfmou8@grzegorz-k50ip>
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!agh.edu.pl!news.agh.edu.pl!news.onet.pl!.POSTED!not-for-mail

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!agh.edu.pl!news.agh.edu.pl!news.onet.pl!.POSTED!not-for-mail
From: greg <adresu@brak.pl>
Newsgroups: pl.comp.lang.java
Subject: Problem z relacjami w derby
Date: Tue, 01 Nov 2011 18:34:17 +0100
Organization: http://onet.pl
Lines: 146
Message-ID: <op.v3923fjrtfmou8@grzegorz-k50ip>
NNTP-Posting-Host: 194-6-207-104.internetia.net.pl
Mime-Version: 1.0
X-Trace: news.onet.pl 1320168858 4249 194.6.207.104 (1 Nov 2011 17:34:18 GMT)
X-Complaints-To: niusy@onet.pl
NNTP-Posting-Date: Tue, 1 Nov 2011 17:34:18 +0000 (UTC)
User-Agent: Opera Mail/11.52 (Linux)
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit