File tree Expand file tree Collapse file tree 1 file changed +38
-0
lines changed
Unit15-JPA/src/unit15/jpa/Actividad23_Aplicacion Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Original file line number Diff line number Diff line change 1+ package unit15 .jpa .Actividad23_Aplicacion ;
2+
3+ import unit15 .jpa .Actividad22_Aplicacion .Barco ;
4+
5+ import java .util .List ;
6+ import java .util .Scanner ;
7+ import javax .persistence .EntityManager ;
8+ import javax .persistence .EntityManagerFactory ;
9+ import javax .persistence .Persistence ;
10+ import javax .persistence .Query ;
11+
12+
13+ public class Main {
14+
15+
16+ public static void main (String [] args ) {
17+ EntityManagerFactory emf
18+ = Persistence .createEntityManagerFactory ("barcosMarinerosPU" );
19+ EntityManager em = emf .createEntityManager ();
20+ System .out .println ("Puesto: " );
21+ String puesto = new Scanner (System .in ).nextLine ();
22+
23+
24+ String jpql = "SELECT b FROM Barco b " +
25+ "WHERE b IN (SELECT m.barco FROM Marinero m " +
26+ "WHERE m.puesto = :puesto)" ;
27+
28+ Query query = em .createQuery (jpql );
29+ query .setParameter ("puesto" , puesto );
30+ List <Barco > barcos = query .getResultList ();
31+
32+ System .out .println ("Barcos con " + puesto );
33+ for (Barco b : barcos ) {
34+ System .out .println (b );
35+ }
36+ }
37+ }
38+
You can’t perform that action at this time.
0 commit comments