0

I fighing with hibernate. I'm trying to follow hibernate.org/ogm/documentation/getting-started/ . Here are my files - persistence.xml:

<?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">
    <!-- Use Hibernate OGM provider: configuration will be transparent -->
    <provider>org.hibernate.ogm.jpa.HibernateOgmPersistence</provider>
    <class>com.mycompany.hibernate.MyEntity</class>
    <properties>
      <property name="hibernate.ogm.datastore.provider" value="MONGODB"/>
      <!-- property optional if you plan and use Infinispan, otherwise adjust to your favorite
                NoSQL Datastore provider.
            <property name="hibernate.ogm.datastore.provider"
                      value="org.hibernate.ogm.datastore.infinispan.impl.InfinispanDatastoreProvider"/>
            -->
      <!-- defines which JTA Transaction we plan to use -->
      <property name="hibernate.ogm.datastore.provider" value="org.hibernate.ogm.datastore.mongodb.impl.MongoDBDatastoreProvider"/>
      <property name="hibernate.transaction.jta.platform" value="org.hibernate.service.jta.platform.internal.JBossStandAloneJtaPlatform"/>
    </properties>
  </persistence-unit>
</persistence>

entity class:

@Entity
@Table(name = "USstates")
public class MyEntity implements Serializable{
   @Id 
   String _id;
   String city;
   Integer pop;
  String state;
  public String getId(){return _id;}
  public String getCity(){return city;}
  public Integer getPop(){return pop;}
  public String getState(){return state;}

} 

application

private static final String JBOSS_TM_CLASS_NAME = "com.mycompany.hibernate.TransactionManager";
    public static void main( String[] args ) throws Exception
    {
        EntityManagerFactory emf = Persistence.createEntityManagerFactory(
    "ogm-jpa-tutorial");

TransactionManager tm = getTransactionManager();
//Persist entities the way you are used to in plain JPA
tm.begin();

EntityManager em = emf.createEntityManager();
MyEntity e = new MyEntity();
e = new MyEntity();
//Retrieve your entities the way you are used to in plain JPA
tm.begin();
em = emf.createEntityManager();
e = em.find(MyEntity.class, "0");
em.flush();
em.close();
tm.commit();

emf.close();

    }

        public static TransactionManager getTransactionManager() {
try {
Class<?> tmClass = App.class.getClassLoader().loadClass( JBOSS_TM_CLASS_NAME );
return (TransactionManager) tmClass.getMethod( "transactionManager" ).invoke( null );
} catch ( ClassNotFoundException e ) {
e.printStackTrace();
} catch ( InvocationTargetException e ) {
e.printStackTrace();
} catch ( NoSuchMethodException e ) {
e.printStackTrace();
} catch ( IllegalAccessException e ) {
e.printStackTrace();
}
return null;
}

I have database test with collection USstates taken from http://media.mongodb.org/zips.json

Using thic codes I got some wornings about logs and what more important exception while running this application:

Exception in thread "main" javax.persistence.PersistenceException: [PersistenceUnit: ogm-jpa-tutorial] Unable to build Hibernate SessionFactory

any ideas?

UPDATE:

after fighting i got an error of non exising class, I already tried milions of combinations of dependency and still got nothing... error:

Exception in thread "main" java.lang.NoClassDefFoundError: org/hibernate/util/xml/Origin

UPDATE 2.0: Now I have other problem:

Exception in thread "main" java.lang.NoSuchMethodError: org.hibernate.cfg.Configuration.getIdentifierGeneratorFactory()Lorg/hibernate/id/factory/spi/MutableIdentifierGeneratorFactory;
    at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:1119)
    at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:291)
    at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:373)
    at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:55)
    at org.hibernate.ogm.jpa.HibernateOgmPersistence.createEntityManagerFactory(HibernateOgmPersistence.java:92)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:63)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:47)
    at com.mycompany.hibernate.App.main(App.java:48)
Saravana
  • 12,647
  • 2
  • 39
  • 57
Kula
  • 125
  • 3
  • 15
  • NoSuchMethodError is clearly inconsistent jars being used. Shame your JPA provider doesn't make it clear what to use, the one I use for MongoDB is simple and just works – Neil Stockton Jul 19 '16 at 13:01

1 Answers1

0

Ok silly question - did you remove the specific connection properties from your persistence.xml here, or did you not have them - example below?

    <property name="hibernate.ogm.datastore.provider" value="mongodb"/>
    <property name="hibernate.ogm.datastore.database" value="rntsmpl"/>
    <property name="hibernate.ogm.datastore.host" value="127.0.0.1"/>
    <property name="hibernate.ogm.datastore.port" value="59541"/>
    <property name="hibernate.ogm.datastore.username" value="admin"/>
    <property name="hibernate.ogm.datastore.password" value="nnTdE2jPf4FV"/>
    <property name="hibernate.transaction.jta.platform"    value="org.hibernate.service.jta.platform.internal.JBossAppServerJtaPlatform" />
qorpus
  • 3
  • 1
  • also you only need this and not <"org.hibernate.ogm.datastore.mongodb.impl.MongoDBDatastoreProvider"/> – qorpus Jul 10 '14 at 02:09
  • how are you accessing it usually? – qorpus Jul 11 '14 at 01:14
  • what dou you mean "usually"? From mongo shell I jużt type test.USstates.find() and This give me 20 first results. I can also access it using Morphia.... – Kula Jul 11 '14 at 19:30
  • currently i got another error of lack of file - see updated post – Kula Jul 12 '14 at 10:51