Hibernate Books

All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: hibernate-ogm mongodb glassfish
PostPosted: Sat Mar 14, 2015 9:12 pm 
Newbie

Joined: Mon Feb 22, 2010 2:07 pm
Posts: 8
Hi
I upgraded hibernate-ogm in my application that runs on glassfish AS from 4.1.0.beta3 to the latest version. That brought an error

Code:
javax.persistence.PersistenceException: [PersistenceUnit: blog-data-pu] Unable to build Hibernate SessionFactory
   at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.persistenceException(EntityManagerFactoryBuilderImpl.java:1239)
   at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.access$600(EntityManagerFactoryBuilderImpl.java:120)
   at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:855)
   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.createContainerEntityManagerFactory(HibernatePersistenceProvider.java:152)
   at org.hibernate.ogm.jpa.HibernateOgmPersistence.createContainerEntityManagerFactory(HibernateOgmPersistence.java:105)
   at org.glassfish.persistence.jpa.PersistenceUnitLoader.loadPU(PersistenceUnitLoader.java:199)
   at org.glassfish.persistence.jpa.PersistenceUnitLoader.<init>(PersistenceUnitLoader.java:107)
   at org.glassfish.persistence.jpa.JPADeployer$1.visitPUD(JPADeployer.java:223)
   at org.glassfish.persistence.jpa.JPADeployer$PersistenceUnitDescriptorIterator.iteratePUDs(JPADeployer.java:510)
   at org.glassfish.persistence.jpa.JPADeployer.createEMFs(JPADeployer.java:230)
   at org.glassfish.persistence.jpa.JPADeployer.prepare(JPADeployer.java:168)
   at com.sun.enterprise.v3.server.ApplicationLifecycle.prepareModule(ApplicationLifecycle.java:925)
   at org.glassfish.javaee.full.deployment.EarDeployer.prepareBundle(EarDeployer.java:309)
   at org.glassfish.javaee.full.deployment.EarDeployer.access$200(EarDeployer.java:88)
   at org.glassfish.javaee.full.deployment.EarDeployer$1.doBundle(EarDeployer.java:155)
   at org.glassfish.javaee.full.deployment.EarDeployer$1.doBundle(EarDeployer.java:152)
   at org.glassfish.javaee.full.deployment.EarDeployer.doOnBundles(EarDeployer.java:232)
   at org.glassfish.javaee.full.deployment.EarDeployer.doOnAllTypedBundles(EarDeployer.java:241)
   at org.glassfish.javaee.full.deployment.EarDeployer.doOnAllBundles(EarDeployer.java:267)
   at org.glassfish.javaee.full.deployment.EarDeployer.prepare(EarDeployer.java:152)
   at com.sun.enterprise.v3.server.ApplicationLifecycle.prepareModule(ApplicationLifecycle.java:925)
   at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:434)
   at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:219)
   at org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:491)
   at com.sun.enterprise.v3.admin.CommandRunnerImpl$2$1.run(CommandRunnerImpl.java:539)
   at com.sun.enterprise.v3.admin.CommandRunnerImpl$2$1.run(CommandRunnerImpl.java:535)
   at java.security.AccessController.doPrivileged(Native Method)
   at javax.security.auth.Subject.doAs(Subject.java:356)
   at com.sun.enterprise.v3.admin.CommandRunnerImpl$2.execute(CommandRunnerImpl.java:534)
   at com.sun.enterprise.v3.admin.CommandRunnerImpl$3.run(CommandRunnerImpl.java:565)
   at com.sun.enterprise.v3.admin.CommandRunnerImpl$3.run(CommandRunnerImpl.java:557)
   at java.security.AccessController.doPrivileged(Native Method)
   at javax.security.auth.Subject.doAs(Subject.java:356)
   at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:556)
   at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1464)
   at com.sun.enterprise.v3.admin.CommandRunnerImpl.access$1300(CommandRunnerImpl.java:109)
   at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1846)
   at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1722)
   at com.sun.enterprise.v3.admin.AdminAdapter.doCommand(AdminAdapter.java:534)
   at com.sun.enterprise.v3.admin.AdminAdapter.onMissingResource(AdminAdapter.java:224)
   at org.glassfish.grizzly.http.server.StaticHttpHandlerBase.service(StaticHttpHandlerBase.java:189)
   at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:459)
   at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:167)
   at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:201)
   at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:175)
   at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:235)
   at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
   at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:284)
   at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:201)
   at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:133)
   at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:112)
   at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
   at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:561)
   at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)
   at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117)
   at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56)
   at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137)
   at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:565)
   at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:545)
   at java.lang.Thread.run(Thread.java:722)
Caused by: org.hibernate.MappingException: Could not get constructor for org.hibernate.ogm.persister.impl.SingleTableOgmEntityPersister
   at org.hibernate.persister.internal.PersisterFactoryImpl.create(PersisterFactoryImpl.java:185)
   at org.hibernate.persister.internal.PersisterFactoryImpl.createEntityPersister(PersisterFactoryImpl.java:135)
   at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:401)
   at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1859)
   at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:852)
   ... 60 more
Caused by: org.hibernate.HibernateException: OGM000068: Could not configure property com.sjs.cms.data.entity.blog.BlogEntryLocalized#status
   at org.hibernate.ogm.persister.impl.OgmEntityPersister.<init>(OgmEntityPersister.java:275)
   at org.hibernate.ogm.persister.impl.SingleTableOgmEntityPersister.<init>(SingleTableOgmEntityPersister.java:35)
   at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
   at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
   at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
   at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
   at org.hibernate.persister.internal.PersisterFactoryImpl.create(PersisterFactoryImpl.java:163)
   ... 64 more
Caused by: org.hibernate.HibernateException: OGM000059: Unable to find a GridType for org.hibernate.type.EnumType
   at org.hibernate.ogm.type.impl.TypeTranslatorImpl.getType(TypeTranslatorImpl.java:100)
   at org.hibernate.ogm.persister.impl.OgmEntityPersister.<init>(OgmEntityPersister.java:272)
   ... 70 more
]]


my persistent.xml

Code:
<persistence version="2.1"
             xmlns="http://xmlns.jcp.org/xml/ns/persistence"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://www.oracle.com/webfolder/technetwork/jsc/xml/ns/persistence/persistence_2_1.xsd">

<persistence-unit name="blog-data-pu" transaction-type="JTA">
        <provider>org.hibernate.ogm.jpa.HibernateOgmPersistence</provider>

        <class>com.sjs.cms.data.entity.blog.BlogEntryLocalized</class>
.......................................
        <exclude-unlisted-classes>true</exclude-unlisted-classes>
        <properties>

            <property name="hibernate.ogm.datastore.provider" value="mongodb"/>

            <property name="hibernate.transaction.jta.platform" value="org.hibernate.service.jta.platform.internal.SunOneJtaPlatform" />

            <property name="hibernate.ogm.datastore.grid_dialect" value="org.hibernate.ogm.datastore.mongodb.MongoDBDialect"/>
            <property name="hibernate.ogm.datastore.database" value="transblog"/>
            <property name="hibernate.ogm.datastore.host" value="localhost"/>

        </properties>
    </persistence-unit>

</persistence>


The field is defined as stated below
Code:
    @Column(name = "status")
    @Enumerated
    private BlogEntryStatus status;


I found a suspitios record in the log file:
Code:
  HHH000400: Using dialect: org.hibernate.ogm.dialect.impl.OgmDialect]]

If I understood the user guide correctly when I specified hibernate.ogm.datastore.grid_dialect property to fully qualified dialect class name, the specified dialect should be used.

Quote:
By default, a datastore provider chooses the best grid dialect transparently but you can manually override that setting with the hibernate.ogm.datastore.grid_dialect option. Use the fully qualified class name of the GridDialect implementation. Most users should ignore this setting entirely and live a happier life instead.


So I would expect org.hibernate.ogm.datastore.mongodb.MongoDBDialect instead of org.hibernate.ogm.dialect.impl.OgmDialect. I am not sure if this leads to the problem though.(Unfortunately there is no happier life without the hibernate.ogm.datastore.grid_dialect option specified as it is stated in the guide)

Related topic is https://forum.hibernate.org/viewtopic.php?f=31&t=1037330. Unfortunately without a solution.
Could you please help with the configuration. Thank you.

My environment is:
Application server: Glassfish 4.1
Hibernate-ogm : 4.1.2
MongoDB

Update:
Actually the reason for this is depicted here
Image
for some reason the type of an enumerated field is not instance of CustomType, but comes as a SerializableType instead which is a successor of the AbstractStandardBasicType. The class on the picture is TypeTranslatorImpl. There is no value in the typeConvertor map for this type. So gridType on the line 99 is NULL and then it fails. Does it really work on JBoss and a standalone apps?


Top
 Profile  
 
 Post subject: Re: hibernate-ogm mongodb glassfish
PostPosted: Wed Mar 18, 2015 4:07 am 
Hibernate Team
Hibernate Team

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

How do you add the Hibernate OGM / ORM libraries to the classpath? Are you adding them as libs to your deployable (WAR, EAR etc.)? Or via some GF-specific mechanism?

I suspect that it is some sort of class loading issue, causing the look-up in ORM's TypeFactory (https://github.com/hibernate/hibernate-orm/blob/master/hibernate-core/src/main/java/org/hibernate/type/TypeFactory.java#L93) to do the wrong thing. Thus it is presented as serializable type in the following rather than as custom type. But that's only an educated guess, we'd need to know some more details of your set-up.

Or, if you could provide a mininum test case which I can build myself and deploy on GlassFish, I could take a look.

Quote:
So I would expect org.hibernate.ogm.datastore.mongodb.MongoDBDialect instead of org.hibernate.ogm.dialect.impl.OgmDialect.


That's alright actually. OgmDialect is Hibernate OGM's (dummy) implementation of Hibernate ORM's Dialect contract. It is not really used with Hibernate OGM, as it is geared towards SQL databases. We still need to plug in an ORM Dialect internally to make things work out with the ORM engine. Hibernate OGM has its own contract (GridDialect) which it uses to talk to NoSQL stores and which MongoDBDialect is an implementation of.

Quote:
Does it really work on JBoss and a standalone apps?


Yes, definitely. There is a test for it here: https://github.com/hibernate/hibernate-ogm/blob/master/core/src/test/java/org/hibernate/ogm/backendtck/type/BuiltInTypeTest.java#L160

--Gunnar

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


Top
 Profile  
 
 Post subject: Re: hibernate-ogm mongodb glassfish
PostPosted: Wed Mar 18, 2015 8:31 am 
Newbie

Joined: Mon Feb 22, 2010 2:07 pm
Posts: 8
Hi Gunnar,
thank you for your answer.

Quote:
How do you add the Hibernate OGM / ORM libraries to the classpath? Are you adding them as libs to your deployable (WAR, EAR etc.)? Or via some GF-specific mechanism?


I do not use any AS specific mechanism. The jars are added to an .ear archive. All but mongodb driver which is in the AS lib directory

Code:

        <!--<hibernate.version>4.3.8.Final</hibernate.version>-->
        <!--<hibernateOgmVersion>4.1.3.Final</hibernateOgmVersion>-->
        <!--<hibernateOgmMongoVersion>4.1.3.Final</hibernateOgmMongoVersion>-->
        <!--<hibernateSearchVersion>5.1.0.Final</hibernateSearchVersion>-->

        <hibernate.version>4.3.5.Final</hibernate.version>
        <hibernateOgmVersion>4.1.0.Beta3</hibernateOgmVersion>
        <hibernateOgmMongoVersion>4.1.0.Beta3</hibernateOgmMongoVersion>
        <hibernateSearchVersion>4.2.0.Beta1</hibernateSearchVersion>
        <mongodb.driver.version>2.12.3</mongodb.driver.version>

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>${hibernate.version}</version>
        </dependency>

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
            <version>${hibernate.version}</version>
        </dependency>

        <dependency>
            <groupId>org.hibernate.ogm</groupId>
            <artifactId>hibernate-ogm-core</artifactId>
            <version>${hibernateOgmVersion}</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate.ogm</groupId>
            <artifactId>hibernate-ogm-mongodb</artifactId>
            <version>${hibernateOgmMongoVersion}</version>
        </dependency>

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-search-orm</artifactId>
            <version>${hibernateSearchVersion}</version>
        </dependency>

        <!--MongoDB Java Driver-->
        <dependency>
            <groupId>org.mongodb</groupId>
            <artifactId>mongo-java-driver</artifactId>
            <version>${mongodb.driver.version}</version>
            <type>jar</type>
            <scope>provided</scope>
        </dependency>



With the versions as they are in the provided snapshot everything works fine. If I use later versions which are commented out in the snapshot, I have the error described in my initial post.

Would it be convenient for you if I create a small app and provide a source code for closer look?


Top
 Profile  
 
 Post subject: Re: hibernate-ogm mongodb glassfish
PostPosted: Thu Mar 19, 2015 2:00 pm 
Hibernate Team
Hibernate Team

Joined: Sat Jan 24, 2009 12:46 pm
Posts: 386
Yes, if you could create a as small as possible (Maven) project which demonstrates that error and which I can build locally, I can try and take a look. Could you open an issue in our JIRA (https://hibernate.atlassian.net/browse/OGM) and attach the project to it (or point me to a project on GitHub etc.)?

Thanks,

--Gunnar

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


Top
 Profile  
 
 Post subject: Re: hibernate-ogm mongodb glassfish
PostPosted: Fri Mar 20, 2015 6:03 pm 
Newbie

Joined: Mon Feb 22, 2010 2:07 pm
Posts: 8
Hi Gunnar,

I have created an issue https://hibernate.atlassian.net/browse/OGM-787

I simplified the code and attached it to the issue. Built with maven, so IDE-agnostic. I am happy to assist if there is any need.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 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.