I am running very simple JPA project
my mapping class is
Code:
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name="simple")
public class Simple {
@Id
@GeneratedValue
@Column(name="pId")
private Long pId;
@Column(name="pname")
private String pname;
@Column(name="page")
private int page;
public Long getpId() {
return pId;
}
public void setpId(Long pId) {
this.pId = pId;
}
public String getPname() {
return pname;
}
public void setPname(String pname) {
this.pname = pname;
}
public int getPage() {
return page;
}
public void setPage(int page) {
this.page = page;
}
}
and persistence.xml file
Code:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.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_2_0.xsd">
<persistence-unit name="ogm-jpa-tutorial" transaction-type="JTA">
<provider>org.hibernate.ogm.jpa.HibernateOgmPersistence</provider>
<class>org.hibernate.mgk.hbi.Simple</class>
<properties>
<property name="hibernate.ogm.datastore.provider" value="MongoDB"/>
<property name="hibernate.ogm.datastore.grid_dialect" value="org.hibernate.ogm.datastore.mongodb.MongoDBDialect"/>
<property name="hibernate.ogm.datastore.database" value="Mgk1"/>
<property name="hibernate.ogm.datastore.host" value="127.0.0.1"/>
<property name="hibernate.ogm.datastore.port" value="27017"/>
</properties>
</persistence-unit>
</persistence>
and my configuration Test.java file
Code:
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import org.hibernate.mgk.hbi.Simple;
public class MgkTest {
public static void main(String[] args) throws Exception{
Simple simple = new Simple();
simple.setPname("zac");
simple.setPage(26);
EntityManagerFactory emf = Persistence.createEntityManagerFactory("ogm-jpa-tutorial" );
System.out.println("persist is doing well");
EntityManager em = emf.createEntityManager();
javax.transaction.UserTransaction tx = com.arjuna.ats.jta.UserTransaction.userTransaction();
{
try {
tx.begin();
em.persist(simple);
tx.commit();
System.out.println("Persist successful ...");
} catch (Exception re) {
tx.rollback();
System.out.println("Persist failed ...");
throw re;
} finally {
if (em != null) {
em.clear();
em.close();
}
}
}
}
}
I am having the following jars
It is running successfully but collection is not creating in database