title: Hibernate: alter table User_Address drop foreign key FK_im39k3og2pvx7vvqdcy35s0g0
body: <p>when i ran my code at first it worked correctly but later i am unable access those 
  tables?</p>
  
  <p>Here is my code:-</p>
  
  <p>hibernate.cfg.xml</p>
  
  <pre><code>&lt;hibernate-configuration&gt;
  
      &lt;session-factory&gt;
  
          &lt;!-- Database connection settings --&gt;
          &lt;property name="connection.driver_class"&gt;com.mysql.jdbc.Driver&lt;/property&gt;
          &lt;property name="connection.url"&gt;jdbc:mysql://localhost:3306/navlic&lt;/property&gt;
          &lt;property name="connection.username"&gt;root&lt;/property&gt;
          &lt;property name="connection.password"&gt;root&lt;/property&gt;
  
          &lt;!-- JDBC connection pool (use the built-in) --&gt;
          &lt;property name="connection.pool_size"&gt;1&lt;/property&gt;
  
          &lt;!-- SQL dialect --&gt;
          &lt;property name="dialect"&gt;org.hibernate.dialect.MySQLDialect&lt;/property&gt;
  
          &lt;!-- Disable the second-level cache  --&gt;
          &lt;property name="cache.provider_class"&gt;org.hibernate.cache.internal.NoCacheProvider&lt;/property&gt;
  
          &lt;!-- Echo all executed SQL to stdout --&gt;
          &lt;property name="show_sql"&gt;true&lt;/property&gt;
  
  
           &lt;!-- Drop and re-create the database schema on startup --&gt;
           &lt;property name="hbm2ddl.auto"&gt;create&lt;/property&gt;          
  
          &lt;mapping class="dto.UserDetails"/&gt;
  
      &lt;/session-factory&gt;
  
  &lt;/hibernate-configuration&gt;
  </code></pre>
  
  <p>Main class:-</p>
  
  <pre><code>package dto;
  
  import java.util.Date;
  
  import javax.persistence.Column;
  import javax.persistence.GenerationType;
  
  import org.hibernate.Session;
  import org.hibernate.SessionFactory;
  import org.hibernate.annotations.CollectionId;
  import org.hibernate.annotations.GenericGenerator;
  import org.hibernate.annotations.Type;
  import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
  import org.hibernate.cfg.Configuration;
  import org.hibernate.service.ServiceRegistry;
  import org.hibernate.service.ServiceRegistryBuilder;
  
  public class HibernateTest {
  
      public static void main(String[] args) {
          UserDetails ud=new UserDetails();
          ud.setUserName("Second user");
  
  
          Address homead=new Address();
          homead.setCity("smg");
          homead.setCountry("aa");
          homead.setHouse("bb");
          homead.setStreet("cc");
          homead.setState("dd");
  
  
          Address officead=new Address();
          officead.setCity("smg");
          officead.setCountry("ee");
          officead.setHouse("ff");
          officead.setStreet("gg");
          officead.setState("hh");
  
  
          ud.getAddr().add(homead);
          ud.getAddr().add(officead);
  
  
              SessionFactory sf;
              ServiceRegistry sr;
              Configuration cfg=new Configuration().configure();
              sr=new StandardServiceRegistryBuilder().applySettings(cfg.getProperties()).build();
              sf=cfg.buildSessionFactory(sr);
  
  
          Session s=sf.openSession();
          s.beginTransaction();
          s.save(ud);
          s.getTransaction().commit();
          s.close();
  
          ud=null;
          s=sf.openSession();
          //if type is lazy it returns only the variables of that class no more reference variables.
          //if type is Eager it returns all the elements of user class
          ud=(UserDetails)s.get(UserDetails.class, 1);
          System.out.println(ud.getAddr().size());
  
  
      }
  
  }
  </code></pre>
  
  <p>Model class:-</p>
  
  <pre><code>@Entity
  public class UserDetails {
  
      @Id
      @GeneratedValue(strategy=GenerationType.AUTO)
      private int UserId;
      private String UserName;
  
  
  
      @ElementCollection(fetch=FetchType.EAGER)
      @JoinTable(name="User_Address",joinColumns=@JoinColumn(name="User_Id"))
      @GenericGenerator(name="hilo-gen" ,strategy="hilo")
      @CollectionId(columns={@Column(name="AddressId")},generator="hilo-gen",type=@Type(type="long"))
      private Collection&lt;Address&gt; addr=new ArrayList&lt;Address&gt;();
  
  
      public Collection&lt;Address&gt; getAddr() {
          return addr;
      }
      public void setAddr(Collection&lt;Address&gt; addr) {
          this.addr = addr;
      }
      public int getUserId() {
          return UserId;
      }
      public void setUserId(int userId) {
          UserId = userId;
      }
      public String getUserName() {
          return UserName;
      }
      public void setUserName(String userName) {
          UserName = userName;
      }
  
  }
  </code></pre>
  
  <p>Address class is here :-</p>
  
  <pre><code>@Embeddable
  public class Address {
      @Column(name="Office_name")
      private String House;
      public String getHouse() {
          return House;
      }
      public void setHouse(String house) {
          House = house;
      }
      public String getStreet() {
          return Street;
      }
      public void setStreet(String street) {
          Street = street;
      }
      public String getCity() {
          return City;
      }
      public void setCity(String city) {
          City = city;
      }
      public String getState() {
          return State;
      }
      public void setState(String state) {
          State = state;
      }
      public String getCountry() {
          return Country;
      }
      public void setCountry(String country) {
          Country = country;
      }
      @Column(name="street_name")
      private String Street;
      @Column(name="city_name")
      private String City;
      @Column(name="state_name")
      private String State;
      @Column(name="country_name")
      private String Country;
  
  
  }
  </code></pre>
  
  <p>when i try to run my code there is no error from hibernate but an mysql error is encountered I am new to mysql can anyone explain me in deatil the cause of this error and how to fix it.</p>
  
  <p>thanks in advance</p>