JPA - join table s daty II

Zdenek Tronicek tronicek na fel.cvut.cz
Neděle Duben 5 21:27:13 CEST 2009


Dobry den,

jde o vztah OneToMany, takze lze presunout sloupec z join tabulky do  
tabulky Vklad. Entita ExpediceVklad pak neni potreba.

Z.T.
-- 
Zdenek Tronicek
Department of Computer Science and Engineering
Prague                   tel: +420 2 2435 7410
http://cs.felk.cvut.cz/~tronicek


Cituji Pavel Zelenka <Zelenka na mediaservis.cz>:

> Zdravim,
>
> jak jsem psal nedavno, potreboval bych vyresit mapovani, kdy "join table"
> obsahuje dlasi hodnotu. Reseni popisovane zde
> http://en.wikibooks.org/wiki/Java_Persistence/ManyToMany#Mapping_a_Join_Table_with_Additional_Columns
> bohuzel u me nefunguje (TopLink Essentials).
> Zkousel jsem se s tim poprat sam, neni to dokonale - nefunguje zapis
> hodnot. Prikladam proto popis mapovani + popis struktury tabulek a byl
> bych vdecny za jakoukoliv pomoc.
>
> Diky
>
> Pavel
>
> @Entity
> public class Expedice implements Serializable {
>     @Id
>     @GeneratedValue(strategy = GenerationType.IDENTITY)
>     private Integer idexpedice;
>     @Temporal(TemporalType.DATE)
>     private Date datum;
>     @OneToMany(fetch = FetchType.EAGER, mappedBy="expedice", cascade =
> CascadeType.ALL)
>     private List<ExpediceVklad> vklady;
>
> @Entity
> public class Vklad implements Serializable {
>     @Id
>     @GeneratedValue(strategy = GenerationType.IDENTITY)
>     private Integer idvklad;
>     private String nazev;
>
>
> @Entity
> @Table(name = "vklad_expedice")
> @IdClass(ExpediceVkladId.class)
> public class ExpediceVklad implements Serializable {
>     @Id
>     private Integer idexpedice;
>     @Id
>     private Integer idvklad;
>     private Integer vaha;
>     @ManyToOne
>     @JoinColumn(name = "idexpedice")
>     private Expedice expedice;
>     @ManyToOne
>     @JoinColumn(name = "idvklad")
>     private Vklad vklad;
>
>
> public class ExpediceVkladId {
>     @Id
>     private Integer idexpedice;
>     @Id
>     private Integer idvklad;
>
>
> Zde je struktura SQL tabulek
>
> EXPEDICE
> idexpedice
> datum
>
> VKLAD
> idvklad
> nazev
>
> VKLAD_EXPEDICE
> idexpedice
> idvklad
> vaha





Další informace o konferenci Konference