-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: Collection is not created in database
PostPosted: Mon Sep 01, 2014 6:07 am 
Newbie

Joined: Sat Aug 23, 2014 12:59 am
Posts: 8
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
Image

It is running successfully but collection is not creating in database


Top
 Profile  
 
 Post subject: Re: Collection is not created in database
PostPosted: Tue Sep 02, 2014 4:38 am 
Newbie

Joined: Sat Aug 23, 2014 12:59 am
Posts: 8
I have got the solution i have not added em.flush() to the persistence.


Top
 Profile  
 
 Post subject: Re: Collection is not created in database
PostPosted: Wed Sep 03, 2014 8:59 am 
Hibernate Team
Hibernate Team

Joined: Sat Jan 24, 2009 12:46 pm
Posts: 388
Hi,

Glad to hear that you managed to solve your issue; You made me curious, though. There should no manual invocation of flush() be required, instead the changes should be written out to the datastore when calling commit() on the transaction object. Any chance you could double-check whether this works? Otherwise there might be something wrong.

Thanks,

--Gunnar

_________________
Visit my blog at http://musingsofaprogrammingaddict.blogspot.com/


Top
 Profile  
 
 Post subject: Re: Collection is not created in database
PostPosted: Fri Sep 05, 2014 5:49 am 
Newbie

Joined: Sat Aug 23, 2014 12:59 am
Posts: 8
I have tried with RESOURCE_LOCAL rather than JTA. Sorry I have forgo-ted to share this.This problem actually raised because I have using tomcat server which doesn't support transactions.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.