title: WildFly + Hibernate
body: <p>I've been struggling for days with configuring Hibernate and run it on WildFly. </p>
  
  <p>Here is my code:</p>
  
  <p>META-INF/persistence.xml</p>
  
  <pre><code>&lt;persistence version="1.0"
           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_1_0.xsd"&gt;
  
  &lt;persistence-unit name="blog" transaction-type="JTA"&gt;
      &lt;provider&gt;org.hibernate.jpa.HibernatePersistenceProvider&lt;/provider&gt;
  
      &lt;properties&gt;
          &lt;property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/blog?createDatabaseIfNotExist=true"/&gt;
          &lt;property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/&gt;
          &lt;property name="hibernate.connection.username" value="abc"/&gt;
          &lt;property name="hibernate.connection.password" value="abc"/&gt;
          &lt;property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect"/&gt;
          &lt;property name="hibernate.hbm2ddl.auto" value="create"/&gt;
          &lt;property name="hibernate.show_sql" value="true"/&gt;
          &lt;property name="jboss.as.jpa.providerModule" value="org.hibernate:5.0"/&gt;
      &lt;/properties&gt;
  
  &lt;/persistence-unit&gt;
  </code></pre>
  
  <p></p>
  
  <p>pom.xml</p>
  
  <pre><code>&lt;dependencies&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;javax&lt;/groupId&gt;
          &lt;artifactId&gt;javaee-api&lt;/artifactId&gt;
          &lt;version&gt;7.0&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;org.hibernate.javax.persistence&lt;/groupId&gt;
          &lt;artifactId&gt;hibernate-jpa-2.1-api&lt;/artifactId&gt;
          &lt;version&gt;1.0.0.Final&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
          &lt;artifactId&gt;hibernate-core&lt;/artifactId&gt;
          &lt;version&gt;5.2.2.Final&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;mysql&lt;/groupId&gt;
          &lt;artifactId&gt;mysql-connector-java&lt;/artifactId&gt;
          &lt;version&gt;5.1.38&lt;/version&gt;
      &lt;/dependency&gt;
  
  &lt;/dependencies&gt;
  
  &lt;properties&gt;
      &lt;maven.compiler.source&gt;1.8&lt;/maven.compiler.source&gt;
      &lt;maven.compiler.target&gt;1.8&lt;/maven.compiler.target&gt;
  &lt;/properties&gt;
  </code></pre>
  
  <p>User: </p>
  
  <pre><code>@Entity
  @Table(name = "users")
  public class User {
  
  @Id
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  private long id;
  
  @Column(name = "username")
  private String username;
  
  @Column(name = "password")
  private String password;
  
  @OneToMany(mappedBy = "user")
  private Set&lt;Post&gt; posts;
  }
  </code></pre>
  
  <p>When I load my main page no database is created.</p>
  
  <p>Moreover I want to persist a User.</p>
  
  <pre><code>@Stateless
  public class UserRepositoryImpl implements UserRepository {
  
  @PersistenceContext(unitName = "blog")
  private EntityManager entityManager;
  
  public void create(User user) {
      this.entityManager.persist(user);
  }
  }
  </code></pre>
  
  <p>No database is created and the entity manager is null. What do I need to configure to make it run?
  I am using IntelliJ for testing.</p>