this : INFO: OGM001207: Connecting to Mongo database named [test]. javax.persistence.PersistenceException: Unable to build entity manager factory at org.hibernate.jpa.HibernatePersistenceProvider.createEntityManagerFactory(HibernatePersistenceProvider.java:83) at org.hibernate.ogm.jpa.HibernateOgmPersistence.createEntityManagerFactory(HibernateOgmPersistence.java:62) at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:55) at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:39) at com.ogm.test.HibernateUtil.test1(HibernateUtil.java:32) at com.ogm.test.HibernateUtil.main(HibernateUtil.java:22) Caused by: org.hibernate.service.spi.ServiceException: OGM000071: Unable to start datatore provider at org.hibernate.ogm.datastore.mongodb.impl.MongoDBDatastoreProvider.start(MongoDBDatastoreProvider.java:115) at org.hibernate.service.internal.AbstractServiceRegistryImpl.startService(AbstractServiceRegistryImpl.java:329) at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:237) at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:206) at org.hibernate.ogm.dialect.impl.GridDialectInitiator.initiateService(GridDialectInitiator.java:48) at org.hibernate.ogm.dialect.impl.GridDialectInitiator.initiateService(GridDialectInitiator.java:32) at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:105) at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:251) at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:225) at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:206) at org.hibernate.ogm.dialect.impl.OgmDialectFactoryInitiator$OgmDialectFactory.<init>(OgmDialectFactoryInitiator.java:51) at org.hibernate.ogm.dialect.impl.OgmDialectFactoryInitiator.buildServiceInstance(OgmDialectFactoryInitiator.java:33) at org.hibernate.ogm.dialect.impl.OgmDialectFactoryInitiator.buildServiceInstance(OgmDialectFactoryInitiator.java:27) at org.hibernate.ogm.service.impl.OptionalServiceInitiator.initiateService(OptionalServiceInitiator.java:23) at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:105) at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:251) at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:225) at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:206) at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:95) at org.hibernate.ogm.service.impl.OgmJdbcServicesInitiator$OgmJdbcServicesImpl.configure(OgmJdbcServicesInitiator.java:56) at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:111) at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:234) at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:206) at org.hibernate.cfg.Configuration.buildTypeRegistrations(Configuration.java:1887) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1845) at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:852) at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:845) at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.withTccl(ClassLoaderServiceImpl.java:398) at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:844) at org.hibernate.jpa.HibernatePersistenceProvider.createEntityManagerFactory(HibernatePersistenceProvider.java:75) ... 5 more Caused by: org.hibernate.HibernateException: OGM001213: MongoDB authentication failed with username [test1] at org.hibernate.ogm.datastore.mongodb.impl.MongoDBDatastoreProvider.extractDatabase(MongoDBDatastoreProvider.java:180) at org.hibernate.ogm.datastore.mongodb.impl.MongoDBDatastoreProvider.start(MongoDBDatastoreProvider.java:110) ... 34 more
this code: package com.ogm.test;
import java.util.logging.Logger;
import javax.persistence.EntityManager; import javax.persistence.EntityManagerFactory; import javax.persistence.Persistence; import javax.transaction.TransactionManager;
public class HibernateUtil3 { private static final Logger log = Logger.getLogger(HibernateUtil3.class.getName());
public static void main(String[] args) { test1(); }
private static void test1() { try { TransactionManager transactionManager = com.arjuna.ats.jta.TransactionManager.transactionManager(); // note that you must start the transaction before creating the // EntityManager // or else call entityManager.joinTransaction() EntityManagerFactory emf = Persistence.createEntityManagerFactory("ogm-jpa-tutorial");
transactionManager.begin();
final EntityManager em = emf.createEntityManager(); Dog poem = new Dog(); poem.setName("L'albatros"); em.persist(poem); transactionManager.commit(); System.out.print(poem.getId()); transactionManager.begin(); poem = em.find(Dog.class, poem.getId()); System.out.print(poem.getId()); em.remove(poem); transactionManager.commit();
em.close();
} catch (Exception e) { e.printStackTrace(); } }
}
this xml:
<?xml version="1.0"?> <persistence 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" version="2.0"> <persistence-unit name="ogm-jpa-tutorial" transaction-type="JTA"> <!-- Use Hibernate OGM provider: configuration will be transparent --> <provider>org.hibernate.ogm.jpa.HibernateOgmPersistence</provider> <properties> <!-- property is optional if you want to use Infinispan, otherwise adjust to your favorite NoSQL Datastore provider. --> <property name="hibernate.ogm.datastore.provider" value="infinispan" /> <property name="hibernate.transaction.jta.platform" value="org.hibernate.engine.transaction.jta.platform.internal.JBossStandAloneJtaPlatform" /> <!-- defines which JTA Transaction we plan to use --> <property name="hibernate.ogm.datastore.provider" value="mongodb" /> <property name="hibernate.ogm.datastore.database" value="test" /> <property name="hibernate.ogm.datastore.host" value="192.168.10.221" /> <property name="hibernate.ogm.datastore.port" value="27017" /> <property name="hibernate.ogm.datastore.username" value="test1"/> <property name="hibernate.ogm.datastore.password" value="test1"/> </properties> </persistence-unit> </persistence>
think you
|