title: Set and Get a column from a table with foreign key in Java using Mysql
body: <p>I'm using Eclipse with Mysql Workbench. I made an application that can create new entries in mysql table but I have a problem. </p>
  
  <p>I have 3 tables: animals(id_animal, name), medics(id_medic, name) and the last one appoinments(id_appoinment, date, id_animal, id_medic) (the id_animal and id_medic from appoinments are foreign keys and the values are taken from animals and medics tables).</p>
  
  <p>To manage connection with datebase i'm using a dbUtil package with EntityManager persistence.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>DatabaseUtil dbUtil = new DatabaseUtil();
  Appoinment appoinment = new Appoinment();
  appoinment.setIdAppoinment(1);
  String date = "2018-12-25"; // YYYY-MM-DD
  java.sql.Date sqlDate = java.sql.Date.valueOf(date);
  appoinment.setDataProgramarii(sqlDate);
  
  appoinment.setAnimal(1); // this line doesn't work
  // here I want to set in appoinments table an animal id from animals table
  appoinment.setMedicID(1); // this line doesn't work
  // here I want to set in appoinments table an medic id from medics table
  
  dbUtil.setUp();
  dbUtil.startTransaction();
  dbUtil.saveAppoinment(appoinment);
  dbUtil.commitTransaction();
  dbUtil.printAllAppoinmentsFromDB();
  dbUtil.closeEntityManager();
  </code></pre>
  
  <p>How can I set the animalID and medicID in appoinment table if they are foreign keys? I already have some animals and medics added to my table so I need to use that id's.</p>
  
  <p>I except this code set an id for animal also for medic from already created tables animals and medics, but says that can't convert int to animal and medic.</p>