hallo leute,
bin neuling im JPA bereich. Schreibe gerade eine Anwendung wo ich JPA verwende. Als Framework nutze ich "Play". Das Framework liefert eine Klasse "Model" die auf JPA/Hibernate aufbaut und einiges vereinfacht.
Mein Problem:
Ich habe probleme mit zwei Tabellen:
- PeriodicalPayment
- Transaction
Transaction speichert einfach nur Kontobewegungen aller Art.
PeriodicalPayment speichert Daueraufträge.
Da die Transactiontabelle unabhängig bleiben soll darf da kein PeriodicalPayment schlüssel rein.
Also brauch ich eine neue Tabelle die mir JPA automatisch erstellt über eine Relation.
Er legt mir auch eine Tabelle für die Realtion an aber leider ohne Primarykey. Und das meckert
mir MySQL an und ist auch nicht schön.
wie kann ich einen Primarykey definieren ohne eine extra Klasse "PeriodicalPaymentTransaction" zu benutzen???
Klasse PeriodicalPayment:
Klasse Transaction:
mfg
bin neuling im JPA bereich. Schreibe gerade eine Anwendung wo ich JPA verwende. Als Framework nutze ich "Play". Das Framework liefert eine Klasse "Model" die auf JPA/Hibernate aufbaut und einiges vereinfacht.
Mein Problem:
Ich habe probleme mit zwei Tabellen:
- PeriodicalPayment
- Transaction
Transaction speichert einfach nur Kontobewegungen aller Art.
PeriodicalPayment speichert Daueraufträge.
Da die Transactiontabelle unabhängig bleiben soll darf da kein PeriodicalPayment schlüssel rein.
Also brauch ich eine neue Tabelle die mir JPA automatisch erstellt über eine Relation.
Er legt mir auch eine Tabelle für die Realtion an aber leider ohne Primarykey. Und das meckert
mir MySQL an und ist auch nicht schön.
wie kann ich einen Primarykey definieren ohne eine extra Klasse "PeriodicalPaymentTransaction" zu benutzen???
Klasse PeriodicalPayment:
Java:
package models;
import play.*;
import play.db.jpa.*;
import javax.persistence.*;
import java.util.*;
@Entity
public class PeriodicalPayment extends Model {
@ManyToOne
public Account account;
@OneToMany(cascade = CascadeType.ALL)
public List<Transaction> transactions;
public int amount;
public String currency;
public Date startAt;
public Date createdAt;
public int periodType;
public PeriodicalPayment(Account account, int amount, String currency, Date startAt, int periodType ) {
this.account = account;
this.transactions = new ArrayList<Transaction>();
this.amount = amount;
this.currency = currency;
this.startAt = startAt;
this.createdAt = new Date();
this.periodType = periodType;
}
}
Klasse Transaction:
Java:
package models;
import play.*;
import play.db.jpa.*;
import javax.persistence.*;
import java.util.*;
@Entity
public class Transaction extends Model {
public int amount;
public String currency;
public Date createdAt;
@ManyToOne
public Account account;
public Transaction(Account account, int amount, String currency) {
this.account = account;
this.amount = amount;
this.currency = currency;
this.createdAt = new Date();
}
}
mfg