JPA创建表

时间:2016-12-03 12:01:03

标签: java mysql hibernate jpa

我遇到MySql和JPA的问题,我尝试用db配置JPA。创建表。

Connectin卡在创建实体经理工厂

  EntityManagerFactory entityManagerFactory =     Persistence.createEntityManagerFactory("JPAService");
    EntityManager entityManager = entityManagerFactory.createEntityManager();

    entityManager.getTransaction().begin();

    UserRole user = new UserRole("USER");
    UserRole admin = new UserRole("ADMIN");
    entityManager.persist(user);
    entityManager.persist(admin);
    User p1 = new User(user, "Pawel", "Brzeczyszczykiewicz", "sdf 17/2", "Krakow", "gty@interia.pl");
    User p2 = new User(admin, "Admin", "Adminowo", "Warszawa", "War", "");
    User p3 = new User(user, "Bogdan", "Łazuka", "Brzeg  12", "Warszawa", "blazuka@op.eu");
    entityManager.persist(p1);
    entityManager.persist(p2);
    entityManager.persist(p3);

    entityManager.getTransaction().commit();
    entityManager.close();
    entityManagerFactory.close();

有我的persistance.xml

<persistence xmlns="http://java.sun.com/xml/ns/persistence"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence" version="1.0">
  <persistence-unit name="JPAService" transaction-type="RESOURCE_LOCAL">
    <properties>

       <!-- Configuring JDBC properties -->
      <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:8080//shop" />
      <property name="javax.persistence.jdbc.user" value="root" />
      <property name="javax.persistence.jdbc.password" value="" />
      <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />

      <!-- Hibernate properties -->
      <property name="hibernate.show_sql" value="true" />
      <property name="hibernate.format_sql" value="true" />
      <property name="hibernate.dialect" value="MySQL5InnoDBDialect" />
      <property name="hibernate.hbm2ddl.auto" value="create" />     


      <!-- Configuring Connection Pool -->
      <property name="hibernate.c3p0.min_size" value="5" />
      <property name="hibernate.c3p0.max_size" value="20" />
      <property name="hibernate.c3p0.timeout" value="500" />
      <property name="hibernate.c3p0.max_statements" value="50" />
      <property name="hibernate.c3p0.idle_test_period" value="2000" />
    </properties>
  </persistence-unit>
</persistence>

我不知道可能是什么原因因为没有听到任何失败而且没有记录

0 个答案:

没有答案