I have an implementation which should create a table in mysql. This is just for testing the function of the code.
But it dosen't and I don't know why, my classes looks like this:
@ManagedBean
@ApplicationScoped
public class Shop {
private List<Artikel> sortiment = new ArrayList<Artikel>();
private static Shop instance = new Shop();
public Shop() {
Artikel a = new Artikel();
a.setId(1);
a.setName("Samsung");
EntityManagerFactory factory = Persistence.createEntityManagerFactory("onlineshop");
EntityManager manager = factory.createEntityManager();
manager.getTransaction().begin();
manager.persist(a);
manager.getTransaction().commit();
}
}
This Class is my Managed Bean class.
And this one is my Persistence Unit:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1"
xmlns="http://ift.tt/1cKbVbQ"
xmlns:xsi="http://ift.tt/ra1lAU"
xsi:schemaLocation="http://ift.tt/1cKbVbQ http://ift.tt/1kMb4sd">
<persistence-unit name="onlineshop" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>
<property name="javax.persistence.jdbc.url" value="jdbc:derby://localhost:1527/onlineshop"/>
<property name="javax.persistence.jdbc.user" value="benjamin"/>
<property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.ClientDriver"/>
<property name="javax.persistence.jdbc.password" value="start123"/>
<property name="hibernate.cache.provider_class" value="org.hibernate.cache.NoCacheProvider"/>
<property name="javax.persistence.schema-generation.database.action" value="create"/>
<property name="hibernate.hbm2ddl.auto" value="create-drop"/>
<property name="hibernate.show_sql" value="true" />
</properties>
</persistence-unit>
</persistence>
And my Entity-Class look like this:
@Entity
public class Artikel implements Serializable{
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private int id;
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
}
So as you can see, it's a very small piece of code, but it won't work for me. All necessary libraries are included, also the mysql.jar file.
Aucun commentaire:
Enregistrer un commentaire