03 JDBC Flashcards

1
Q

@ Tabelle

A

@Entity

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

@ Tabelle hat in Datenbank anderen Namen

A

@Table(name = “echterName”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

@ Über Primärschlüssel

A

@Id

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

@ nach Primärschlüssel wenn Id automatisch erstellt werden soll

A

@GeneratedValue

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

@ 1 zu n

A

MUSS IN n DB SEIN

@ManyToOne
@JoinedColumn( name=”NameDesFremdschluessels”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

// EntityManager erzeugen (Name der Persistence Unit: uni)

A
entityManagerFactory= Persistance.createEntityManagerFactory("uni");
entityManager = entityManagerFactory.createEntityManager()
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

// Studiengang mit ID 5 aus Datenbank laden

A

entityManager.getTransaction().begin();
Studiengang studiengang = entityManager.find(Studiengang.class,5);
entityManager.getTransaction().commit();
System.out.println(studiengang.toString());

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q
// alle Studenten, die den Studiengang "IBAIT" studieren,
// aus Datenbank laden
A

TypedQuery tp = entityManager.createQuery(“SELECT s FROM Student s WHERE s.studiengang.name = ‘IBAIT’ “ , Student.class);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

List ibaitStudenten =

A

List ibaitStudenten = tp.getResultList();

for (Student s : ibaitStudenten){
System.out.println(s);
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q
// neue Studentin speichern
// Vorname: Petra, Nachname: Schmidt,
// Matrikelnr.: 1234, Studiengang-ID: 5
A

entityManager.getTransaction().begin();

Student neueStudentin = new Student();
neueStudentin.vorname = "Petra";
neueStudentin.nachname = "Schmidt";
neueStudentin.matrikelnr = 1234;
neueStudentin.studiengang.setId(5);
entityManager.persist(neueStudentin);

entityManager.getTransaction().commit();

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q
} finally {
// Ressourcen schließen
A
if (entityManager ! = null) {
    entityManager.close();
}
if (entityManagerFactory ! = null) {
    entityManagerFactory.close();}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

@ n:m

A

@ManyToMany
@JoinTable(
name= “HilfsDatenbankname”,
joinColumns = {@JoinColumn (name = “FremdschlusselEigenerDatenbank”)},
inverseJoinColumns = {@JoinColumn (name = “FremdschlusselAndereDB”)}
)

private Set <
andererTablename > neuertext;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

@ 1:1

A

@OneToOne

@JoinColumn (name=”andererFS”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Speichern (neu erzeugtes Object )

A

em.persist(kunde);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly