-->
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.  [ 13 posts ] 
Author Message
 Post subject: Hibernate ORM to Hibernate OGM
PostPosted: Thu Nov 20, 2014 10:24 am 
Newbie

Joined: Thu Nov 20, 2014 10:05 am
Posts: 15
Hello,

this is my first post in this forum and i hope somebody can help me. If additional informations are needed just tell me.

What i have:
A running Maven project which has an native implementation of Hibernate, so no JPA with Hibernate. All classes get correctly mapped and are annotated.

What i want:
Migrate to Hibernate OGM with the nosql-database MongoDB.

The problem:
When buildSessionFactory(serviceRegistry); is called following exceptions are triggered:
Code:
java.lang.ExceptionInInitializerError
   at hibernate.HibernateUtil.<clinit>(HibernateUtil.java:26)
   at hibernate.HibernateStore.StoreApiRequest(HibernateStore.java:189)
   at request.manager.GetMessagesRequestManager.search(GetMessagesRequestManager.java:59)
   at request.endpoints.RestMessageService.searchInPlattforms(RestMessageService.java:83)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
   at java.lang.reflect.Method.invoke(Unknown Source)
   at com.sun.jersey.spi.container.JavaMethodInvokerFactory$1.invoke(JavaMethodInvokerFactory.java:60)
   at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$TypeOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:185)
   at com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75)
   at com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:302)
   at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
   at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108)
   at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
   at com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84)
   at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1542)
   at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1473)
   at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1419)
   at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1409)
   at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:409)
   at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:540)
   at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:715)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
   at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
   at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:503)
   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:136)
   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
   at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
   at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:526)
   at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1078)
   at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:655)
   at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:222)
   at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1566)
   at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1523)
   at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
   at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
   at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
   at java.lang.Thread.run(Unknown Source)
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 hibernate.HibernateUtil.<clinit>(HibernateUtil.java:21)
   ... 45 more
Caused by: org.hibernate.HibernateException: OGM000059: Unable to find a GridType for java.util.ArrayList
   at org.hibernate.ogm.type.impl.TypeTranslatorImpl.getType(TypeTranslatorImpl.java:94)
   at org.hibernate.ogm.persister.impl.OgmEntityPersister.<init>(OgmEntityPersister.java:265)
   at org.hibernate.ogm.persister.impl.SingleTableOgmEntityPersister.<init>(SingleTableOgmEntityPersister.java:35)
   at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
   at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
   at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
   at java.lang.reflect.Constructor.newInstance(Unknown Source)
   at org.hibernate.persister.internal.PersisterFactoryImpl.create(PersisterFactoryImpl.java:163)
   ... 49 more
org.hibernate.HibernateException: OGM000059: Unable to find a GridType for java.util.ArrayList
   at org.hibernate.ogm.type.impl.TypeTranslatorImpl.getType(TypeTranslatorImpl.java:94)
   at org.hibernate.ogm.persister.impl.OgmEntityPersister.<init>(OgmEntityPersister.java:265)
   at org.hibernate.ogm.persister.impl.SingleTableOgmEntityPersister.<init>(SingleTableOgmEntityPersister.java:35)
   at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
   at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
   at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
   at java.lang.reflect.Constructor.newInstance(Unknown Source)
   at org.hibernate.persister.internal.PersisterFactoryImpl.create(PersisterFactoryImpl.java:163)
   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 hibernate.HibernateUtil.<clinit>(HibernateUtil.java:21)
   at hibernate.HibernateStore.StoreApiRequest(HibernateStore.java:189)
   at request.manager.GetMessagesRequestManager.search(GetMessagesRequestManager.java:59)
   at request.endpoints.RestMessageService.searchInPlattforms(RestMessageService.java:83)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
   at java.lang.reflect.Method.invoke(Unknown Source)
   at com.sun.jersey.spi.container.JavaMethodInvokerFactory$1.invoke(JavaMethodInvokerFactory.java:60)
   at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$TypeOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:185)
   at com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75)
   at com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:302)
   at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
   at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108)
   at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
   at com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84)
   at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1542)
   at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1473)
   at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1419)
   at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1409)
   at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:409)
   at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:540)
   at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:715)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
   at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
   at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:503)
   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:136)
   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
   at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
   at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:526)
   at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1078)
   at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:655)
   at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:222)
   at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1566)
   at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1523)
   at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
   at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
   at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
   at java.lang.Thread.run(Unknown Source)


Here the relevant code parts:
My Util:
Code:
public class HibernateUtil {
   
    private static final SessionFactory sessionFactory; 
    private static final ServiceRegistry serviceRegistry; 
     
    static { 
       OgmConfiguration conf = new OgmConfiguration(); 
        conf.configure(); 
        serviceRegistry = new StandardServiceRegistryBuilder().applySettings(conf.getProperties()).build();
        try { 
            sessionFactory = conf.buildSessionFactory(serviceRegistry); 
        } catch (Exception e) { 
            throw new ExceptionInInitializerError(e); 
        }         
    } 
     
    public static SessionFactory getSessionFactory() { 
        return sessionFactory; 
    }
}

My hibernate.cfg.xml:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
      "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
      "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
      
<hibernate-configuration>
    <session-factory>
       <property name="hibernate.transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</property>
    <property name="hibernate.transaction.jta.platform">org.hibernate.service.jta.platform.internal.JBossStandAloneJtaPlatform</property>
   <property name="hibernate.ogm.datastore.provider">mongodb</property>
   <property name="hibernate.ogm.datastore.database">test</property>
        <property name="current_session_context_class">thread</property>
       
        <!-- OLD ORM CONNECTION DATA
        <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/sma</property>
        <property name="hibernate.dialect">hibernate.HibernateDialect</property>
        <property name="hibernate.connection.username">root</property>
        <property name="hibernate.connection.password">helloworld</property>
        <property name="current_session_context_class">thread</property>
        <property name="hbm2ddl.auto">update</property>
        <property name="hibernate.connection.pool_size">10</property>
        <property name="show_sql">true</property>
        <property name="hibernate.connection.useUnicode">true</property>
        <property name="hibernate.connection.characterEncoding">UTF-8</property>
        <property name="hibernate.connection.charSet">UTF-8</property>
    -->
      
   <mapping class="opensocial.data.PluralField"></mapping>
        <mapping class="opensocial.data.Address"></mapping>
        <mapping class="opensocial.data.Album"></mapping>
   <mapping class="crawljob.Crawljob"></mapping>      
        <mapping class="opensocial.data.Collection"></mapping>
        <mapping class="opensocial.data.Group"></mapping>
        <mapping class="opensocial.data.MediaItem"></mapping>
        <mapping class="opensocial.data.MediaLink"></mapping>
        <mapping class="opensocial.data.Message"></mapping>
        <mapping class="opensocial.data.Name"></mapping>
        <mapping class="opensocial.data.ObjectId"></mapping>
        <mapping class="opensocial.data.Person"></mapping>
        <mapping class="opensocial.extensions.Address"></mapping>
        <mapping class="opensocial.extensions.Coordinate"></mapping>
        <mapping class="opensocial.extensions.CoordinateCollection"></mapping>
        <mapping class="opensocial.extensions.Message"></mapping>
        <mapping class="opensocial.extensions.ObjectId"></mapping>
        <mapping class="opensocial.extensions.Person"></mapping>
        <mapping class="opensocial.extensions.ApiRequest"></mapping>
       
    </session-factory>
</hibernate-configuration>


A SNAPSHOT out of my pom.xml:
Code:
mongo-java-driver: 2.12.4
hibernate-ogm-core: 4.1.0.Beta8
hibernate-ogm-mongodb: 4.1.0.Beta8
hibernate-jpa-2.1-api: 1.0.0.Final
hibernate-core: 4.3.9.Final


Top
 Profile  
 
 Post subject: Re: Hibernate ORM to Hibernate OGM
PostPosted: Fri Nov 21, 2014 6:27 am 
Hibernate Team
Hibernate Team

Joined: Fri Sep 09, 2011 3:18 am
Posts: 295
Hi,
could you create a test case or at least show us the mapping of the entities?

Thanks,
Davide


Top
 Profile  
 
 Post subject: Re: Hibernate ORM to Hibernate OGM
PostPosted: Fri Nov 21, 2014 6:59 am 
Newbie

Joined: Thu Nov 20, 2014 10:05 am
Posts: 15
Thank you for the fast response, by the way mongo receives connection, the mappings looks like the following:
I have a base class:
Code:
<mapping class="opensocial.data.Address"></mapping>

Code:
package opensocial.data;

import javax.persistence.DiscriminatorColumn;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import flexjson.JSON;
import javax.persistence.InheritanceType;
import javax.persistence.GeneratedValue;
import javax.persistence.DiscriminatorType;

@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "ClassType",discriminatorType = DiscriminatorType.STRING)
public class Address{

   /**
    * The building identifier. Discussion
    */
   protected String building;

   /**
    * @return the building:
    * The building identifier. Discussion
    */
   public String getBuilding() {
       return this.building;
   }

   /**
    * @param building the building to set:
    * The building identifier. Discussion
    */
   public void setBuilding(String building) {
       this.building = building;
   }

   /**
    * The country name component.
    */
   protected String country;

   /**
    * @return the country:
    * The country name component.
    */
   public String getCountry() {
       return this.country;
   }

   /**
    * @param country the country to set:
    * The country name component.
    */
   public void setCountry(String country) {
       this.country = country;
   }

   /**
    * The floor identifier. Discussion
    */
   protected String floor;

   /**
    * @return the floor:
    * The floor identifier. Discussion
    */
   public String getFloor() {
       return this.floor;
   }

   /**
    * @param floor the floor to set:
    * The floor identifier. Discussion
    */
   public void setFloor(String floor) {
       this.floor = floor;
   }

   /**
    * The full mailing address, formatted for display or use with a mailing
    * label. This field MAY contain newlines. This is the Primary Sub-Field for
    * this field, for the purposes of sorting and filtering.
    */
   protected String formatted;

   /**
    * @return the formatted:
    * The full mailing address, formatted for display or use with a mailing
    * label. This field MAY contain newlines. This is the Primary Sub-Field for
    * this field, for the purposes of sorting and filtering.
    */
   public String getFormatted() {
       return this.formatted;
   }

   /**
    * @param formatted the formatted to set:
    * The full mailing address, formatted for display or use with a mailing
    * label. This field MAY contain newlines. This is the Primary Sub-Field for
    * this field, for the purposes of sorting and filtering.
    */
   public void setFormatted(String formatted) {
       this.formatted = formatted;
   }

   /**
    * Expresses the latitude of the location on a map.
    */
   protected String latitude;

   /**
    * @return the latitude:
    * Expresses the latitude of the location on a map.
    */
   public String getLatitude() {
       return this.latitude;
   }

   /**
    * @param latitude the latitude to set:
    * Expresses the latitude of the location on a map.
    */
   public void setLatitude(String latitude) {
       this.latitude = latitude;
   }

   /**
    * The city or locality component.
    */
   protected String locality;

   /**
    * @return the locality:
    * The city or locality component.
    */
   public String getLocality() {
       return this.locality;
   }

   /**
    * @param locality the locality to set:
    * The city or locality component.
    */
   public void setLocality(String locality) {
       this.locality = locality;
   }

   /**
    * Expresses the longitude of the location on a map.
    */
   protected String longitude;

   /**
    * @return the longitude:
    * Expresses the longitude of the location on a map.
    */
   public String getLongitude() {
       return this.longitude;
   }

   /**
    * @param longitude the longitude to set:
    * Expresses the longitude of the location on a map.
    */
   public void setLongitude(String longitude) {
       this.longitude = longitude;
   }

   /**
    * The zipcode or postal code component.
    */
   protected String postalCode;

   /**
    * @return the postalCode:
    * The zipcode or postal code component.
    */
   public String getPostalCode() {
       return this.postalCode;
   }

   /**
    * @param postalCode the postalCode to set:
    * The zipcode or postal code component.
    */
   public void setPostalCode(String postalCode) {
       this.postalCode = postalCode;
   }

   /**
    * The state or region component.
    */
   protected String region;

   /**
    * @return the region:
    * The state or region component.
    */
   public String getRegion() {
       return this.region;
   }

   /**
    * @param region the region to set:
    * The state or region component.
    */
   public void setRegion(String region) {
       this.region = region;
   }

   /**
    * The full street address component, which may include house number,
    * street name, PO BOX, and multi-line extended street address information.
    * This field MAY contain newlines.
    */
   protected String streetAddress;

   /**
    * @return the streetAddress:
    * The full street address component, which may include house number,
    * street name, PO BOX, and multi-line extended street address information.
    * This field MAY contain newlines.
    */
   public String getStreetAddress() {
       return this.streetAddress;
   }

   /**
    * @param streetAddress the streetAddress to set:
    * The full street address component, which may include house number,
    * street name, PO BOX, and multi-line extended street address information.
    * This field MAY contain newlines.
    */
   public void setStreetAddress(String streetAddress) {
       this.streetAddress = streetAddress;
   }

   /**
    * The address type or label. Examples include 'work', 'home'.
    */
   protected String type;

   /**
    * @return the type:
    * The address type or label. Examples include 'work', 'home'.
    */
   public String getType() {
       return this.type;
   }

   /**
    * @param type the type to set:
    * The address type or label. Examples include 'work', 'home'.
    */
   public void setType(String type) {
       this.type = type;
   }

   /**
    * primary key for hibernate
    */
   @Id
   @GeneratedValue
   @JSON(include = false)
   private int pk_Address;

   /**
    * @return the pk_Address:
    * primary key for hibernate
    */
   @JSON(include=false)
   public int getPk_Address() {
       return this.pk_Address;
   }

   /**
    * @param pk_Address the pk_Address to set:
    * primary key for hibernate
    */
   public void setPk_Address(int pk_Address) {
       this.pk_Address = pk_Address;
   }

}


And i have a extension class:
Code:
<mapping class="opensocial.extensions.Address"></mapping>

Code:
package opensocial.extensions;

import java.util.HashMap;

import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;

import opensocial.data.HibernateDeepStorable;

import org.hibernate.Session;

@Entity(name = "opensocial.extensions.Address")
public class Address extends opensocial.data.Address implements HibernateDeepStorable{
   
   private String countryCode;
   
   @OneToOne
   @JoinColumn(name="fk_coordinates")
   private CoordinateCollection coordinates;

   /**
    * @return the countryCode
    */
   public String getCountryCode() {
      return countryCode;
   }

   /**
    * @param countryCode the countryCode to set
    */
   public void setCountryCode(String countryCode) {
      this.countryCode = countryCode;
   }

   /**
    * @return the coordinates
    */
   public CoordinateCollection getCoordinates() {
      return coordinates;
   }

   /**
    * @param coordinates the coordinates to set
    */
   public void setCoordinates(CoordinateCollection coordinates) {
      this.coordinates = coordinates;
   }
   
   protected String name;
   
   /**
    * @return the name
    */
   public String getName() {
      return name;
   }

   /**
    * @param name the name to set
    */
   public void setName(String name) {
      this.name = name;
   }
   
   protected String url;

   @Override
   public boolean hibernateStore(Session session, ApiRequest apiRequest, boolean isRootObject, boolean checkForDuplicates, HashMap<String, HashMap<String, Object>> hashmap, Object outDuplicate) {
      if(coordinates != null)
         coordinates.hibernateStore(session, apiRequest, false, checkForDuplicates, hashmap, null);
      session.save(this);
      return false;
   }

   /**
    * @return the url
    */
   public String getUrl() {
      return url;
   }

   /**
    * @param url the url to set
    */
   public void setUrl(String url) {
      this.url = url;
   }
}


Top
 Profile  
 
 Post subject: Re: Hibernate ORM to Hibernate OGM
PostPosted: Mon Nov 24, 2014 4:12 am 
Hibernate Team
Hibernate Team

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

apparently there is one entity which has list-typed property (ArrayList) but it is not marked as an association via @OneToMany/@ManyToMany. Maybe in one of the other entities? I'm going to improve the logging in that case so that the exception mentions the concerned property.

--Gunnar

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


Top
 Profile  
 
 Post subject: Re: Hibernate ORM to Hibernate OGM
PostPosted: Tue Nov 25, 2014 6:55 am 
Newbie

Joined: Thu Nov 20, 2014 10:05 am
Posts: 15
Ok, may relevant as additional information i updated my hibernate core version from 4.1.9 to 4.3.9 and my hibernate-jpa from 2.0 to 2.1. In pure Orm with the old versions the relational mapping was working.

I will look into the other entities to maybe identify the properties.

/*EDIT*/

I think i found the problem maybe:

The property "protected ArrayList<Object> list;" i googled and found that Hibernate automaps "List" and not "ArrayList"
So i turned all my ArrayList properties into List and annotaded them e.g.:
Code:
@Column
@ElementCollection(targetClass=String.class)
protected List<String> mediaType;


But like on stackoverflow http://stackoverflow.com/questions/11358567/elementcollection-for-mapping-list-of-object-class written Objects are not supported via JPA. I think when i change to List from ArrayList i don't need the @OneToMany annotation?

The following shows the mapping class:
Code:
@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "ClassType",discriminatorType = DiscriminatorType.STRING)
public class Collection{

   /**
    * The index of the first result returned in this response,
    * relative to the starting index of all results that would be returned if
    * no startIndex had been requested. In general, this will be equal to the
    * value requested by the startIndex, or 0 if no specific startIndex was
    * requested.
    */
   protected int startIndex;

   /**
    * @return the startIndex:
    * The index of the first result returned in this response,
    * relative to the starting index of all results that would be returned if
    * no startIndex had been requested. In general, this will be equal to the
    * value requested by the startIndex, or 0 if no specific startIndex was
    * requested.
    */
   public int getStartIndex() {
       return this.startIndex;
   }

   /**
    * @param startIndex the startIndex to set:
    * The index of the first result returned in this response,
    * relative to the starting index of all results that would be returned if
    * no startIndex had been requested. In general, this will be equal to the
    * value requested by the startIndex, or 0 if no specific startIndex was
    * requested.
    */
   public void setStartIndex(int startIndex) {
       this.startIndex = startIndex;
   }

   /**
    * The number of results returned per page in this response.
    * In general, this will be equal to the count Query Parameter,
    * but MAY be less if the Service Provider is unwilling to return as many
    * results per page as requested, or if there are less than the requested
    * number of results left to return when starting at the current startIndex.
    */
   protected int itemsPerPage;

   /**
    * @return the itemsPerPage:
    * The number of results returned per page in this response.
    * In general, this will be equal to the count Query Parameter,
    * but MAY be less if the Service Provider is unwilling to return as many
    * results per page as requested, or if there are less than the requested
    * number of results left to return when starting at the current startIndex.
    */
   public int getItemsPerPage() {
       return this.itemsPerPage;
   }

   /**
    * @param itemsPerPage the itemsPerPage to set:
    * The number of results returned per page in this response.
    * In general, this will be equal to the count Query Parameter,
    * but MAY be less if the Service Provider is unwilling to return as many
    * results per page as requested, or if there are less than the requested
    * number of results left to return when starting at the current startIndex.
    */
   public void setItemsPerPage(int itemsPerPage) {
       this.itemsPerPage = itemsPerPage;
   }

   /**
    * The total number of data that would be returned if
    * there were no startIndex or count specified. This value tells the
    * Consumer how many total results to expect, regardless of the current
    * pagination being used, but taking into account the current filtering
    * options in the request.
    */
   protected int totalResults;

   /**
    * @return the totalResults:
    * The total number of data that would be returned if
    * there were no startIndex or count specified. This value tells the
    * Consumer how many total results to expect, regardless of the current
    * pagination being used, but taking into account the current filtering
    * options in the request.
    */
   public int getTotalResults() {
       return this.totalResults;
   }

   /**
    * @param totalResults the totalResults to set:
    * The total number of data that would be returned if
    * there were no startIndex or count specified. This value tells the
    * Consumer how many total results to expect, regardless of the current
    * pagination being used, but taking into account the current filtering
    * options in the request.
    */
   public void setTotalResults(int totalResults) {
       this.totalResults = totalResults;
   }

   /**
    * An array of objects, one for each item matching the request.
    * For consistency of parsing, if the
    * request could possibly return multiple items (as is normally the case),
    * this value MUST always be an array of results, even if there
    * happens to be
    * 0 or 1 matching results. (i.e. "list": [ { * first item * },
    * { * seond item * } ]).
    */
   protected ArrayList<Object> list;

   /**
    * @return the list:
    * An array of objects, one for each item matching the request.
    * For consistency of parsing, if the
    * request could possibly return multiple items (as is normally the case),
    * this value MUST always be an array of results, even if there
    * happens to be
    * 0 or 1 matching results. (i.e. "list": [ { * first item * },
    * { * seond item * } ]).
    */
   public ArrayList<Object> getList() {
       return this.list;
   }

   /**
    * @param list the list to set:
    * An array of objects, one for each item matching the request.
    * For consistency of parsing, if the
    * request could possibly return multiple items (as is normally the case),
    * this value MUST always be an array of results, even if there
    * happens to be
    * 0 or 1 matching results. (i.e. "list": [ { * first item * },
    * { * seond item * } ]).
    */
   public void setList(ArrayList<Object> list) {
       this.list = list;
   }

   /**
    * indicating if the result honors filter params in the
    * request. The default value is 'true' if the field does not
    * exist.
    */
   protected Boolean filtered;

   /**
    * @return the filtered:
    * indicating if the result honors filter params in the
    * request. The default value is 'true' if the field does not
    * exist.
    */
   public Boolean getFiltered() {
       return this.filtered;
   }

   /**
    * @param filtered the filtered to set:
    * indicating if the result honors filter params in the
    * request. The default value is 'true' if the field does not
    * exist.
    */
   public void setFiltered(Boolean filtered) {
       this.filtered = filtered;
   }

   /**
    * Indicating if the items are sorted. The default value is
    * 'true' if the field does not exist.
    */
   protected Boolean sorted;

   /**
    * @return the sorted:
    * Indicating if the items are sorted. The default value is
    * 'true' if the field does not exist.
    */
   public Boolean getSorted() {
       return this.sorted;
   }

   /**
    * @param sorted the sorted to set:
    * Indicating if the items are sorted. The default value is
    * 'true' if the field does not exist.
    */
   public void setSorted(Boolean sorted) {
       this.sorted = sorted;
   }

   /**
    * Indicating if the result honors the updatedSince param in
    * the request. The default value is 'true' if the field does not
    * exist.
    */
   protected Boolean updatedSince;

   /**
    * @return the updatedSince:
    * Indicating if the result honors the updatedSince param in
    * the request. The default value is 'true' if the field does not
    * exist.
    */
   public Boolean getUpdatedSince() {
       return this.updatedSince;
   }

   /**
    * @param updatedSince the updatedSince to set:
    * Indicating if the result honors the updatedSince param in
    * the request. The default value is 'true' if the field does not
    * exist.
    */
   public void setUpdatedSince(Boolean updatedSince) {
       this.updatedSince = updatedSince;
   }

   /**
    * primary key for hibernate
    */
   @Id
   @GeneratedValue
   @JSON(include = false)
   private int pk_Collection;

   /**
    * @return the pk_Collection:
    * primary key for hibernate
    */
   @JSON(include=false)
   public int getPk_Collection() {
       return this.pk_Collection;
   }

   /**
    * @param pk_Collection the pk_Collection to set:
    * primary key for hibernate
    */
   public void setPk_Collection(int pk_Collection) {
       this.pk_Collection = pk_Collection;
   }

}


Top
 Profile  
 
 Post subject: Re: Hibernate ORM to Hibernate OGM
PostPosted: Wed Nov 26, 2014 3:49 am 
Hibernate Team
Hibernate Team

Joined: Sat Jan 24, 2009 12:46 pm
Posts: 388
There is a semantic difference between @ElementCollection and @OneToMany; The former represents a collection of primitives / embeddable types whose lifecycle is fully dependent on the embedding object, whereas the latter represents an association to entities whose lifecycle is independent from the referencing entity. You'd have to use either of the two, not both.

Using List rather than ArrayList makes sense as it allows Hibernate to plug-in its own collection implementations for supporting lazy-loading etc.

Hth,

--Gunnar

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


Top
 Profile  
 
 Post subject: Re: Hibernate ORM to Hibernate OGM
PostPosted: Fri Nov 28, 2014 8:55 am 
Newbie

Joined: Thu Nov 20, 2014 10:05 am
Posts: 15
Okay, that's logic to me now. @ElementCollection for primitives and @OneToMany for association. But at the moment i have problems with the following property:

Code:
   @Column
   @OneToMany(fetch = FetchType.LAZY, mappedBy = "collection", targetEntity= Object.class)
   protected List<Object> list;

   public List<Object> getList() {
       return this.list;
   }

   public void setList(List<Object> list) {
       this.list = list;
   }


The exception for that:

Code:
java.lang.ExceptionInInitializerError
   at hibernate.HibernateUtil.<clinit>(HibernateUtil.java:20)
   at hibernate.HibernateStore.StoreApiRequest(HibernateStore.java:189)
   at request.manager.GetMessagesRequestManager.search(GetMessagesRequestManager.java:59)
   at request.endpoints.RestMessageService.searchInPlattforms(RestMessageService.java:83)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
   at java.lang.reflect.Method.invoke(Unknown Source)
   at com.sun.jersey.spi.container.JavaMethodInvokerFactory$1.invoke(JavaMethodInvokerFactory.java:60)
   at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$TypeOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:185)
   at com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75)
   at com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:302)
   at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
   at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108)
   at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
   at com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84)
   at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1542)
   at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1473)
   at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1419)
   at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1409)
   at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:409)
   at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:540)
   at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:715)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
   at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
   at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:503)
   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:136)
   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
   at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
   at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:526)
   at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1078)
   at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:655)
   at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:222)
   at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1566)
   at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1523)
   at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
   at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
   at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
   at java.lang.Thread.run(Unknown Source)
Caused by: org.hibernate.AnnotationException: Use of @OneToMany or @ManyToMany targeting an unmapped class: opensocial.data.Collection.list[java.lang.Object]
   at org.hibernate.cfg.annotations.CollectionBinder.bindManyToManySecondPass(CollectionBinder.java:1134)
   at org.hibernate.cfg.annotations.CollectionBinder.bindStarToManySecondPass(CollectionBinder.java:793)
   at org.hibernate.cfg.annotations.CollectionBinder$1.secondPass(CollectionBinder.java:728)
   at org.hibernate.cfg.CollectionSecondPass.doSecondPass(CollectionSecondPass.java:70)
   at org.hibernate.cfg.Configuration.originalSecondPassCompile(Configuration.java:1697)
   at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1426)
   at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1846)
   at hibernate.HibernateUtil.<clinit>(HibernateUtil.java:18)
   ... 45 more


It is very important, that this property can deal with the "Object"-Type.

Thanks in advanceand greetings^^


Top
 Profile  
 
 Post subject: Re: Hibernate ORM to Hibernate OGM
PostPosted: Fri Nov 28, 2014 6:31 pm 
Hibernate Team
Hibernate Team

Joined: Sat Jan 24, 2009 12:46 pm
Posts: 388
Quote:
@ElementCollection for primitives


It's not only primitives, also @Embeddedable types. See section 2.5 of the JPA spec.

Quote:
It is very important, that this property can deal with the "Object"-Type.


That's not going to work. You must declare the list to be of another entity type, e.g. List<MyOtherEntity> list; Object itself is no entity type.

--Gunnar

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


Top
 Profile  
 
 Post subject: Re: Hibernate ORM to Hibernate OGM
PostPosted: Tue Dec 02, 2014 5:35 am 
Newbie

Joined: Thu Nov 20, 2014 10:05 am
Posts: 15
Ok, thank you i still need to learn some conventions. I started a work around with an entity so i think OGM doesn't have any problem now with this list anymore.

But now i have the following exception, i apologize if it is trivial. It is a big problem for me that it doesn't tell me WHERE the specific property is:

Code:
org.hibernate.HibernateException: OGM000059: Unable to find a GridType for [Ljava.lang.String;
   org.hibernate.ogm.type.impl.TypeTranslatorImpl.getType(TypeTranslatorImpl.java:94)
   org.hibernate.ogm.persister.impl.OgmEntityPersister.<init>(OgmEntityPersister.java:265)
   org.hibernate.ogm.persister.impl.SingleTableOgmEntityPersister.<init>(SingleTableOgmEntityPersister.java:35)
   sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
   sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
   sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
   java.lang.reflect.Constructor.newInstance(Unknown Source)
   org.hibernate.persister.internal.PersisterFactoryImpl.create(PersisterFactoryImpl.java:163)
   org.hibernate.persister.internal.PersisterFactoryImpl.createEntityPersister(PersisterFactoryImpl.java:135)
   org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:401)
   org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1859)
   hibernate.HibernateUtil.<clinit>(HibernateUtil.java:18)
   hibernate.HibernateStore.StoreApiRequest(HibernateStore.java:189)
   request.manager.GetMessagesRequestManager.search(GetMessagesRequestManager.java:59)
   request.endpoints.RestMessageService.searchInPlattforms(RestMessageService.java:83)
   sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
   sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
   java.lang.reflect.Method.invoke(Unknown Source)
   com.sun.jersey.spi.container.JavaMethodInvokerFactory$1.invoke(JavaMethodInvokerFactory.java:60)
   com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$TypeOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:185)
   com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75)
   com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:302)
   com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
   com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108)
   com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
   com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84)
   com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1542)
   com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1473)
   com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1419)
   com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1409)
   com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:409)
   com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:540)
   com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:715)
   javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
   org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)


I should say, that i mapped ALL my List<String>properties the way:
Code:
   @Column
   @ElementCollection(targetClass=String.class)
   protected List<String> mediaType;

   public List<String> getMediaType() {
       return this.mediaType;
   }

   public void setMediaType(List<String> mediaType) {
       this.mediaType = mediaType;
   }


Best regards


Top
 Profile  
 
 Post subject: Re: Hibernate ORM to Hibernate OGM
PostPosted: Tue Dec 02, 2014 8:38 am 
Hibernate Team
Hibernate Team

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

Based on "Unable to find a GridType for [Ljava.lang.String;" I'd say you have an array of strings (i.e. String[]) rather then List<String> somewhere.

Yes, it's annoying that it doesn't tell you which property is affected atm. That's improved on master already; so if you feel adventureous, you could build Hibernate OGM yourself from the sources (https://github.com/hibernate/hibernate-ogm) and use that snapshot version. This should tell you which property is the problem.

Hth,

--Gunnar

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


Top
 Profile  
 
 Post subject: Re: Hibernate ORM to Hibernate OGM
PostPosted: Tue Dec 09, 2014 8:55 am 
Newbie

Joined: Thu Nov 20, 2014 10:05 am
Posts: 15
Thank you a lot, it works now the collections get saved into my MongoDB :). Now i run into a new problem querying my db.
An example of what an entry in my collection i try to query looks like:
Code:
{
  "_id": 2473,
  "num_dislikes": 0,
  "body": "#Hochwasser #STORKAU @ #ELBE ---> #Pegel auf 1531 cm gestiegen. [Stand: 11:00]",
  "fk_apiRequest": 12,
  "fk_sender": 2472,
  "senderId": "twitter:240646015",
  "type": "PUBLIC_MESSAGE",
  "num_votes": 0,
  "ClassType": "Message",
  "num_comments": 0,
  "num_likes": 0,
  "num_views": 0,
  "num_shares": 0,
  "rating": 0,
  "messageId": "twitter:537548900153180161",
  "timeSent": {"$date": "2014-11-26T11:10:19.000+0100"}
}


Now here my mapped basic class and the extension class:
Code:
package opensocial.data;


import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

import javax.persistence.Access;
import javax.persistence.AccessType;
import javax.persistence.CascadeType;
import javax.persistence.CollectionTable;
import javax.persistence.Column;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.DiscriminatorType;
import javax.persistence.ElementCollection;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Transient;

import opensocial.extensions.ApiRequest;
import opensocial.extensions.HibernateDeepStorableExtension;

import org.hibernate.Session;
import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;

import flexjson.JSON;

/**
* Valid definitions for Message-Field are listed in the table below.A Message example follows. For brevity, details of the 'sender' field,
* an OpenSocial Person, are omitted. The recipient may also include a type identifier. The osapi:recipient
* supports two formats: The 'sender' field in the message representations is only needed when
* receiving a message with a GET request. It is not required when POSTING a
* new message as this information is represented by the {guid}. Using a
* Person for the sender field allows a gadget to present meaningful
* information about the message sender without requiring a separate request
* for this information.The 'data' field is used for information specific to the gadget that is
* sending or displaying the message. It may be omitted in most messages. An
* example is a message from a user asking to join a group. In the received
* message to the group's owner(s), the 'data' field could contain the JSON or
* XML representation of an OpenSocial Group.
*/
@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "ClassType",discriminatorType = DiscriminatorType.STRING)
public class Message implements HibernateDeepStorable, HibernateCheckForDuplicates{

   /**
    * Identifies the application that generated this message.
    */
   protected String appUrl;

   /**
    * @return the appUrl:
    * Identifies the application that generated this message.
    */
   public String getAppUrl() {
       return this.appUrl;
   }

   /**
    * @param appUrl the appUrl to set:
    * Identifies the application that generated this message.
    */
   public void setAppUrl(String appUrl) {
       this.appUrl = appUrl;
   }

   /**
    * The main text of the message. HTML attributes are allowed and
    * are sanitized by the container.
    */
   @Column(columnDefinition="TEXT")
   protected String body;

   /**
    * @return the body:
    * The main text of the message. HTML attributes are allowed and
    * are sanitized by the container.
    */
   public String getBody() {
       return this.body;
   }

   /**
    * @param body the body to set:
    * The main text of the message. HTML attributes are allowed and
    * are sanitized by the container.
    */
   public void setBody(String body) {
       this.body = body;
   }

   /**
    * The main text of the message as a message template. Specifies
    * the message ID to use in the gadget xml.
    */
   protected String bodyId;

   /**
    * @return the bodyId:
    * The main text of the message as a message template. Specifies
    * the message ID to use in the gadget xml.
    */
   public String getBodyId() {
       return this.bodyId;
   }

   /**
    * @param bodyId the bodyId to set:
    * The main text of the message as a message template. Specifies
    * the message ID to use in the gadget xml.
    */
   public void setBodyId(String bodyId) {
       this.bodyId = bodyId;
   }

   /**
    * Identifies the messages collection IDs this message is
    * contained in.
    */
    @Column
   @ElementCollection(targetClass=java.lang.String.class)
   protected List<String> collectionIds;

   /**
    * @return the collectionIds:
    * Identifies the messages collection IDs this message is
    * contained in.
    */
   public List<String> getCollectionIds() {
       return this.collectionIds;
   }

   /**
    * @param collectionIds the collectionIds to set:
    * Identifies the messages collection IDs this message is
    * contained in.
    */
   public void setCollectionIds(List<String> collectionIds) {
       this.collectionIds = collectionIds;
   }

   /**
    * Unique ID for this message.
    */
   @Transient
   protected ObjectId id;

   /**
    * @return the id:
    * Unique ID for this message.
    */
   public ObjectId getId() {
       return this.id;
   }

   /**
    * @param id the id to set:
    * Unique ID for this message.
    */
   public void setId(ObjectId id) {
       this.id = id;
   }

   /**
    * @return the id:
    * Used to store id as simple String in Hibernate (instead of relation)
    */
   @Column(name = "messageId")
   @JSON(include = false)
   protected String messageId;
   
   public String getPseudoId() {
      if(id != null){
          return this.id.toString();
      }else{
         return null;
      }
   }


   /**
    * @param id the id to set:
    * Used to store id as simple String in Hibernate (instead of relation)
    */
   public void setPseudoId(String id) {if(id!= null)
          this.id = new opensocial.extensions.ObjectId(id);
   }

   /**
    * Message ID of a parent resource, use for threaded comments/messages. References the
    * semantics of the Atom Threading model defined in rfc4685. URLs
    * should be mapped to Atom &lt;link rel="type" .../&gt;
    */
   @Transient
   protected ObjectId inReplyTo;

   /**
    * @return the inReplyTo:
    * Message ID of a parent resource, use for threaded comments/messages. References the
    * semantics of the Atom Threading model defined in rfc4685. URLs
    * should be mapped to Atom &lt;link rel="type" .../&gt;
    */
   public ObjectId getInReplyTo() {
       return this.inReplyTo;
   }

   /**
    * @param inReplyTo the inReplyTo to set:
    * Message ID of a parent resource, use for threaded comments/messages. References the
    * semantics of the Atom Threading model defined in rfc4685. URLs
    * should be mapped to Atom &lt;link rel="type" .../&gt;
    */
   public void setInReplyTo(ObjectId inReplyTo) {
       this.inReplyTo = inReplyTo;
   }

   /**
    * @return the inReplyTo:
    * Used to store inReplyTo as simple String in Hibernate (instead of relation)
    */
   @Column(name = "inReplyTo")
   @Access(value = AccessType.PROPERTY)
   @JSON(include = false)
   public String getPseudoInReplyTo() {
      if(inReplyTo != null)
          return this.inReplyTo.toString();
      else
   return null;
   }


   /**
    * @param inReplyTo the inReplyTo to set:
    * Used to store inReplyTo as simple String in Hibernate (instead of relation)
    */
   public void setPseudoInReplyTo(String inReplyTo) {if(inReplyTo!= null)
          this.inReplyTo = new opensocial.extensions.ObjectId(inReplyTo);
   }

   /**
    * Array of person IDs.
    */
   @Transient
   protected List<ObjectId> recipients;

   /**
    * @return the recipients:
    * Array of person IDs.
    */
   public List<ObjectId> getRecipients() {
       return this.recipients;
   }

   /**
    * @param recipients the recipients to set:
    * Array of person IDs.
    */
   public void setRecipients(List<ObjectId> recipients) {
       this.recipients = recipients;
   }

   /**
    * @return the recipients:
    * Used to store recipients as simple String in Hibernate (instead of relation)
    */
   @Access(value = AccessType.PROPERTY)
   @ElementCollection(targetClass=java.lang.String.class)
   @CollectionTable(name="Message_recipients", joinColumns=@JoinColumn(name="pk_message"))
   @Column(name = "recipients")
   @LazyCollection(LazyCollectionOption.FALSE)
   @JSON(include = false)
   public List<String> getPseudoRecipients() {
      if(recipients != null){
         List<String> returnList = new ArrayList<String>();
         for(ObjectId item : recipients)
            returnList.add(item.toString());
         return returnList;
      }
      return null;
   }


   /**
    * @param recipients the recipients to set:
    * Used to store recipients as simple String in Hibernate (instead of relation)
    */
   public void setPseudoRecipients(List<String> list) {
      if(list != null){
         recipients = new ArrayList<ObjectId>();
         for(String item : list)
            recipients.add(new opensocial.extensions.ObjectId(item));
         }
         else
            recipients = null;
   }

   /**
    * Array of message ids indicating responses to this message. References the semantics
    * of the Atom Threading model defined in rfc4685. URLs should be mapped to
    * Atom &lt;link rel="type" .../&gt;
    */
   @Transient
   protected List<ObjectId> replies;

   /**
    * @return the replies:
    * Array of message ids indicating responses to this message. References the semantics
    * of the Atom Threading model defined in rfc4685. URLs should be mapped to
    * Atom &lt;link rel="type" .../&gt;
    */
   public List<ObjectId> getReplies() {
       return this.replies;
   }

   /**
    * @param replies the replies to set:
    * Array of message ids indicating responses to this message. References the semantics
    * of the Atom Threading model defined in rfc4685. URLs should be mapped to
    * Atom &lt;link rel="type" .../&gt;
    */
   public void setReplies(List<ObjectId> replies) {
       this.replies = replies;
   }

   /**
    * @return the replies:
    * Used to store replies as simple String in Hibernate (instead of relation)
    */
   @Access(value = AccessType.PROPERTY)
   @ElementCollection(targetClass=java.lang.String.class)
   @CollectionTable(name="Message_replies", joinColumns=@JoinColumn(name="pk_message"))
   @Column(name = "replies")
   @LazyCollection(LazyCollectionOption.FALSE)
   @JSON(include = false)
   public List<String> getPseudoReplies() {
      if(replies != null){
         List<String> returnList = new ArrayList<String>();
         for(ObjectId item : replies)
            returnList.add(item.toString());
         return returnList;
      }
      return null;
   }


   /**
    * @param replies the replies to set:
    * Used to store replies as simple String in Hibernate (instead of relation)
    */
   public void setPseudoReplies(List<String> list) {
      if(list != null){
         replies = new ArrayList<ObjectId>();
         for(String item : list)
            replies.add(new opensocial.extensions.ObjectId(item));
         }
         else
            replies = null;
   }

   /**
    * Id of person who sent the message.
    */
   @Transient
   protected ObjectId senderId;

   /**
    * @return the senderId:
    * Id of person who sent the message.
    */
   public ObjectId getSenderId() {
       return this.senderId;
   }

   /**
    * @param senderId the senderId to set:
    * Id of person who sent the message.
    */
   public void setSenderId(ObjectId senderId) {
       this.senderId = senderId;
   }

   /**
    * @return the senderId:
    * Used to store senderId as simple String in Hibernate (instead of relation)
    */
   @Column(name = "senderId")
   @Access(value = AccessType.PROPERTY)
   @JSON(include = false)
   public String getPseudoSenderId() {
      if(senderId != null)
          return this.senderId.toString();
      else
   return null;
   }


   /**
    * @param senderId the senderId to set:
    * Used to store senderId as simple String in Hibernate (instead of relation)
    */
   public void setPseudoSenderId(String senderId) {if(senderId!= null)
          this.senderId = new opensocial.extensions.ObjectId(senderId);
   }

   /**
    * Status of the message. (NEW, READ, DELETED).
    */
   protected String status;

   /**
    * @return the status:
    * Status of the message. (NEW, READ, DELETED).
    */
   public String getStatus() {
       return this.status;
   }

   /**
    * @param status the status to set:
    * Status of the message. (NEW, READ, DELETED).
    */
   public void setStatus(String status) {
       this.status = status;
   }

   /**
    * UTC time message was sent.
    */
   protected Date timeSent;

   /**
    * @return the timeSent:
    * UTC time message was sent.
    */
   public Date getTimeSent() {
       return this.timeSent;
   }

   /**
    * @param timeSent the timeSent to set:
    * UTC time message was sent.
    */
   public void setTimeSent(Date timeSent) {
       this.timeSent = timeSent;
   }

   /**
    * The title of the message. HTML attributes are allowed and are
    * sanitized by the container.
    */
   protected String title;

   /**
    * @return the title:
    * The title of the message. HTML attributes are allowed and are
    * sanitized by the container.
    */
   public String getTitle() {
       return this.title;
   }

   /**
    * @param title the title to set:
    * The title of the message. HTML attributes are allowed and are
    * sanitized by the container.
    */
   public void setTitle(String title) {
       this.title = title;
   }

   /**
    * The title of the message as a message template. Specifies the
    * message ID to use in the gadget xml.
    */
   protected String titleId;

   /**
    * @return the titleId:
    * The title of the message as a message template. Specifies the
    * message ID to use in the gadget xml.
    */
   public String getTitleId() {
       return this.titleId;
   }

   /**
    * @param titleId the titleId to set:
    * The title of the message as a message template. Specifies the
    * message ID to use in the gadget xml.
    */
   public void setTitleId(String titleId) {
       this.titleId = titleId;
   }

   /**
    * The type of the message.
    */
   protected String type;

   /**
    * @return the type:
    * The type of the message.
    */
   public String getType() {
       return this.type;
   }

   /**
    * @param type the type to set:
    * The type of the message.
    */
   public void setType(String type) {
       this.type = type;
   }

   /**
    * Last update for this message.
    */
   protected Date updated;

   /**
    * @return the updated:
    * Last update for this message.
    */
   public Date getUpdated() {
       return this.updated;
   }

   /**
    * @param updated the updated to set:
    * Last update for this message.
    */
   public void setUpdated(Date updated) {
       this.updated = updated;
   }

   /**
    * List of related URLs for this message. Supported URL types
    * include 'alternate', alternate for for this mailbox (text/html
    * being the most common).
    */
   @OneToOne
   @JoinColumn(name = "fk_urls")
   protected PluralField urls;

   /**
    * @return the urls:
    * List of related URLs for this message. Supported URL types
    * include 'alternate', alternate for for this mailbox (text/html
    * being the most common).
    */
   public PluralField getUrls() {
       return this.urls;
   }

   /**
    * @param urls the urls to set:
    * List of related URLs for this message. Supported URL types
    * include 'alternate', alternate for for this mailbox (text/html
    * being the most common).
    */
   public void setUrls(PluralField urls) {
       this.urls = urls;
   }

   /**
    * Message ID of a parent resource, use for threaded comments/messages. References the
    * semantics of the Atom Threading model defined in rfc4685. URLs
    * should be mapped to Atom &lt;link rel="type" .../&gt;
    */
   @OneToOne
   @JoinColumn(name = "fk_inReplyToMessage")
   protected Message inReplyToMessage;

   /**
    * @return the inReplyToMessage:
    * Message ID of a parent resource, use for threaded comments/messages. References the
    * semantics of the Atom Threading model defined in rfc4685. URLs
    * should be mapped to Atom &lt;link rel="type" .../&gt;
    */
   public Message getInReplyToMessage() {
       return this.inReplyToMessage;
   }

   /**
    * @param inReplyToMessage the inReplyToMessage to set:
    * Message ID of a parent resource, use for threaded comments/messages. References the
    * semantics of the Atom Threading model defined in rfc4685. URLs
    * should be mapped to Atom &lt;link rel="type" .../&gt;
    */
   public void setInReplyToMessage(Message inReplyToMessage) {
       this.inReplyToMessage = inReplyToMessage;
   }

   /**
    * Array of person IDs.
    */
   @OneToMany(cascade=CascadeType.ALL)
   @LazyCollection(LazyCollectionOption.FALSE)
   @JoinTable(name="Message_Person_mapping", joinColumns = @JoinColumn(name = "pk_Message"), inverseJoinColumns = @JoinColumn(name = "pk_Person"))
   @ElementCollection(targetClass = Person.class)
   protected List<Person> recipientPersons;

   /**
    * @return the recipientPersons:
    * Array of person IDs.
    */
   public List<Person> getRecipientPersons() {
       return this.recipientPersons;
   }

   /**
    * @param recipientPersons the recipientPersons to set:
    * Array of person IDs.
    */
   public void setRecipientPersons(List<Person> recipientPersons) {
       this.recipientPersons = recipientPersons;
   }

   /**
    * Array of message ids indicating responses to this message. References the semantics
    * of the Atom Threading model defined in rfc4685. URLs should be mapped to
    * Atom &lt;link rel="type" .../&gt;
    */
   @OneToMany(cascade=CascadeType.ALL)
   @LazyCollection(LazyCollectionOption.FALSE)
   @JoinTable(name="Message_Message_mapping", joinColumns = @JoinColumn(name = "pk_Message"), inverseJoinColumns = @JoinColumn(name = "pk_Message_replyMessages"))
   @ElementCollection(targetClass = Message.class)
   protected List<Message> replyMessages;

   /**
    * @return the replyMessages:
    * Array of message ids indicating responses to this message. References the semantics
    * of the Atom Threading model defined in rfc4685. URLs should be mapped to
    * Atom &lt;link rel="type" .../&gt;
    */
   public List<Message> getReplyMessages() {
       return this.replyMessages;
   }

   /**
    * @param replyMessages the replyMessages to set:
    * Array of message ids indicating responses to this message. References the semantics
    * of the Atom Threading model defined in rfc4685. URLs should be mapped to
    * Atom &lt;link rel="type" .../&gt;
    */
   public void setReplyMessages(List<Message> replyMessages) {
       this.replyMessages = replyMessages;
   }

   /**
    * Id of person who sent the message.
    */
   @OneToOne
   @JoinColumn(name = "fk_sender")
   protected Person sender;

   /**
    * @return the sender:
    * Id of person who sent the message.
    */
   public Person getSender() {
       return this.sender;
   }

   /**
    * @param sender the sender to set:
    * Id of person who sent the message.
    */
   public void setSender(Person sender) {
       this.sender = sender;
   }

   /**
    * primary key for hibernate
    */
   @Id
   @GeneratedValue
   @JSON(include = false)
   private int pk_Message;

   /**
    * @return the pk_Message:
    * primary key for hibernate
    */
   @JSON(include=false)
   public int getPk_Message() {
       return this.pk_Message;
   }

   /**
    * @param pk_Message the pk_Message to set:
    * primary key for hibernate
    */
   public void setPk_Message(int pk_Message) {
       this.pk_Message = pk_Message;
   }

   @Override
   public boolean hibernateStore(Session session, ApiRequest apiRequest, boolean isRootObject, boolean checkForDuplicates, HashMap<String, HashMap<String, Object>> hashmap, Object duplicateOut){
      Object foundDuplicate = null;
      if(!checkForDuplicates || !(this instanceof HibernateCheckForDuplicates) || !((HibernateCheckForDuplicates)this).hibernateCheckForDuplicates(session, apiRequest, hashmap, foundDuplicate)){
         System.out.println("Okay Go");
         if(urls != null)
            session.save(urls);
         if(inReplyToMessage != null)
            if(inReplyToMessage.hibernateStore(session, apiRequest, false, checkForDuplicates, hashmap, foundDuplicate))
               inReplyToMessage = (Message) foundDuplicate;
         if(recipientPersons != null)
            for(int i = 0; i < recipientPersons.size(); i++)
               if(recipientPersons.get(i).hibernateStore(session, apiRequest, false, checkForDuplicates, hashmap, foundDuplicate))
                  recipientPersons.set(i, (Person) foundDuplicate);
         if(replyMessages != null)
            for(int i = 0; i < replyMessages.size(); i++)
               if(replyMessages.get(i).hibernateStore(session, apiRequest, false, checkForDuplicates, hashmap, foundDuplicate))
                  replyMessages.set(i, (Message) foundDuplicate);
         if(sender != null)
            if(sender.hibernateStore(session, apiRequest, false, checkForDuplicates, hashmap, foundDuplicate))
               sender = (Person) foundDuplicate;
         if(this instanceof HibernateDeepStorableExtension)
            ((HibernateDeepStorableExtension) this).hibernateStoreExtension(session, apiRequest, isRootObject, checkForDuplicates, hashmap);
         session.save(this);
         if(this instanceof HibernateCheckForDuplicates)
            ((HibernateCheckForDuplicates) this).hibernateAddToHashmap(hashmap);
         return false;
      }
      else{
         duplicateOut = foundDuplicate;
         return true;
      }
   }

   @Override
   public boolean hibernateCheckForDuplicates(Session session, ApiRequest api, HashMap<String, HashMap<String, Object>> hashmap, Object duplicateOut){
      Object foundDuplicate = null;
      //First step: check for tmp Objects
      //System.out.println(getId().toString());
      if(hashmap.containsKey("Message")){
         if(hashmap.get("Message").containsKey(getId().toString())){
            foundDuplicate = hashmap.get("Message").get(getId().toString());
         }
      }
      //Second step: check for Objects in Database, if duplicate not found in first step
      if(foundDuplicate == null){
          Message obj = (Message) session.createQuery("from Message as m where m.messageId = '"+this.getPseudoId()+"' and m.apiRequest = '"+api.getApirequest_primary()+"'").uniqueResult();
         if(obj != null)
            foundDuplicate = obj;
      }
      //process results of both steps
      duplicateOut = foundDuplicate;
      return (foundDuplicate != null);
   }

   @Override
   public void hibernateAddToHashmap(HashMap<String, HashMap<String, Object>> hashmap){
      HashMap<String, Object> hashMapToPut = hashmap.get("Message");
      if(hashMapToPut == null){
         hashMapToPut = new HashMap<String, Object>();
         hashmap.put("Message", hashMapToPut);
      }
      hashMapToPut.put(this.getId().toString(), this);
   }
}


Code:
package opensocial.extensions;


import java.util.HashMap;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.DiscriminatorValue;
import javax.persistence.ElementCollection;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;

import opensocial.data.MediaItem;
import opensocial.data.MediaLink;

import org.hibernate.Session;

import flexjson.JSON;
/**
* Valid definitions for Message-Field are listed in the table below.A Message example follows. For brevity, details of the 'sender' field,
* an OpenSocial Person, are omitted. The recipient may also include a type identifier. The osapi:recipient
* supports two formats: The 'sender' field in the message representations is only needed when
* receiving a message with a GET request. It is not required when POSTING a
* new message as this information is represented by the {guid}. Using a
* Person for the sender field allows a gadget to present meaningful
* information about the message sender without requiring a separate request
* for this information.The 'data' field is used for information specific to the gadget that is
* sending or displaying the message. It may be omitted in most messages. An
* example is a message from a user asking to join a group. In the received
* message to the group's owner(s), the 'data' field could contain the JSON or
* XML representation of an OpenSocial Group.
*/
@Entity(name = "opensocial.extensions.Message")
@DiscriminatorValue("Message")
public class Message extends opensocial.data.Message implements HibernateDeepStorableExtension {

   @OneToOne
   @JoinColumn(name = "fk_address")
   private Address address;

   @OneToOne
   @JoinColumn(name = "fk_coordinates")
   private CoordinateCollection coordinates;

   @OneToMany(cascade = CascadeType.ALL, fetch=FetchType.EAGER)
   @JoinTable(name = "Message_MediaItem_mapping", joinColumns = @JoinColumn(name = "pk_Message"), inverseJoinColumns = @JoinColumn(name = "pk_MediaItem"))
   @ElementCollection(targetClass=MediaItem.class)
   private List<MediaItem> mediaItems;

   @OneToOne
   @JoinColumn(name = "fk_mediaLink")
   private MediaLink mediaLink;

   @OneToOne
   @JoinColumn(name = "fk_apiRequest")
   @JSON(include = false)
   private ApiRequest apiRequest;

   private int num_comments;

   private int num_dislikes;

   private int num_likes;

   private int num_shares;

   private int num_views;

   private int num_votes;

   private int rating;

   @Override
   public void hibernateStoreExtension(Session session, ApiRequest apiRequest,
         boolean isRootObject, boolean checkForDuplicates, HashMap<String, HashMap<String, Object>> hashmap) {
      if(apiRequest != null && isRootObject && this.apiRequest == null)
         this.apiRequest = apiRequest;
      if(this.address != null)
         address.hibernateStore(session, apiRequest, false, checkForDuplicates, hashmap, null);
      if(this.coordinates != null)
         coordinates.hibernateStore(session, apiRequest, false, checkForDuplicates, hashmap, null);
      if(this.mediaItems != null)
         for(MediaItem item : this.mediaItems)
            item.hibernateStore(session, apiRequest, false, checkForDuplicates, hashmap, null);
      if(this.mediaLink != null)
         mediaLink.hibernateStore(session, apiRequest, false, checkForDuplicates, hashmap, null);
   }
   
   /**
    * @return the address
    */
   public Address getAddress() {
      return address;
   }

   /**
    * @param address the address to set
    */
   public void setAddress(Address address) {
      this.address = address;
   }

   /**
    * @return the coordinates
    */
   public CoordinateCollection getCoordinates() {
      return coordinates;
   }

   /**
    * @param coordinates the coordinates to set
    */
   public void setCoordinates(CoordinateCollection coordinates) {
      this.coordinates = coordinates;
   }

   /**
    * @return the mediaItems
    */
   public List<MediaItem> getMediaItems() {
      return mediaItems;
   }

   /**
    * @param mediaItems the mediaItems to set
    */
   public void setMediaItems(List<MediaItem> mediaItems) {
      this.mediaItems = mediaItems;
   }

   /**
    * @return the mediaLink
    */
   public MediaLink getMediaLink() {
      return mediaLink;
   }

   /**
    * @param mediaLink the mediaLink to set
    */
   public void setMediaLink(MediaLink mediaLink) {
      this.mediaLink = mediaLink;
   }

   

   /**
    * @return the num_comments
    */
   public int getNum_comments() {
      return num_comments;
   }

   /**
    * @param num_comments the num_comments to set
    */
   public void setNum_comments(int num_comments) {
      this.num_comments = num_comments;
   }

   /**
    * @return the num_dislikes
    */
   public int getNum_dislikes() {
      return num_dislikes;
   }

   /**
    * @param num_dislikes the num_dislikes to set
    */
   public void setNum_dislikes(int num_dislikes) {
      this.num_dislikes = num_dislikes;
   }

   /**
    * @return the num_likes
    */
   public int getNum_likes() {
      return num_likes;
   }

   /**
    * @param num_likes the num_likes to set
    */
   public void setNum_likes(int num_likes) {
      this.num_likes = num_likes;
   }

   /**
    * @return the num_shares
    */
   public int getNum_shares() {
      return num_shares;
   }

   /**
    * @param num_shares the num_shares to set
    */
   public void setNum_shares(int num_shares) {
      this.num_shares = num_shares;
   }

   /**
    * @return the num_views
    */
   public int getNum_views() {
      return num_views;
   }

   /**
    * @param num_views the num_views to set
    */
   public void setNum_views(int num_views) {
      this.num_views = num_views;
   }

   /**
    * @return the num_votes
    */
   public int getNum_votes() {
      return num_votes;
   }

   /**
    * @param num_votes the num_votes to set
    */
   public void setNum_votes(int num_votes) {
      this.num_votes = num_votes;
   }

   /**
    * @return the rating
    */
   public int getRating() {
      return rating;
   }

   /**
    * @param rating the rating to set
    */
   public void setRating(int rating) {
      this.rating = rating;
   }

   /**
    * @return the apiRequest
    */
   public ApiRequest getApiRequest() {
      return apiRequest;
   }

   /**
    * @param apiRequest the apiRequest to set
    */
   public void setApiRequest(ApiRequest apiRequest) {
      this.apiRequest = apiRequest;
   }

}


Now when i try to query my db with:
Code:
Message obj = (Message) session.createQuery("from Message as m where m.messageId = '"+this.getPseudoId()+"' and m.apiRequest = '"+api.getApirequest_primary()+"'").uniqueResult();


I get the exception:
Code:
java.lang.UnsupportedOperationException: Queries on associated entities are not supported yet.
   at org.hibernate.ogm.datastore.mongodb.query.parsing.impl.MongoDBPropertyHelper.convertToPropertyType(MongoDBPropertyHelper.java:41)
   at org.hibernate.hql.ast.spi.SingleEntityQueryBuilder.addComparisonPredicate(SingleEntityQueryBuilder.java:83)
   at org.hibernate.hql.ast.spi.SingleEntityQueryRendererDelegate.addComparisonPredicate(SingleEntityQueryRendererDelegate.java:231)
   at org.hibernate.hql.ast.spi.SingleEntityQueryRendererDelegate.predicateEquals(SingleEntityQueryRendererDelegate.java:209)
   at org.hibernate.hql.ast.render.QueryRenderer.predicate(QueryRenderer.java:5197)
   at org.hibernate.hql.ast.render.QueryRenderer.searchCondition(QueryRenderer.java:4871)
   at org.hibernate.hql.ast.render.QueryRenderer.searchCondition(QueryRenderer.java:4807)
   at org.hibernate.hql.ast.render.QueryRenderer.whereClause(QueryRenderer.java:2347)
   at org.hibernate.hql.ast.render.QueryRenderer.querySpec(QueryRenderer.java:2202)
   at org.hibernate.hql.ast.render.QueryRenderer.queryExpression(QueryRenderer.java:2105)
   at org.hibernate.hql.ast.render.QueryRenderer.queryStatement(QueryRenderer.java:1744)
   at org.hibernate.hql.ast.render.QueryRenderer.queryStatementSet(QueryRenderer.java:1657)
   at org.hibernate.hql.ast.render.QueryRenderer.statement(QueryRenderer.java:653)
   at org.hibernate.hql.ast.spi.QueryRendererProcessor.process(QueryRendererProcessor.java:51)
   at org.hibernate.hql.QueryParser.parseQuery(QueryParser.java:82)
   at org.hibernate.ogm.datastore.mongodb.query.parsing.impl.MongoDBBasedQueryParserService.parseQuery(MongoDBBasedQueryParserService.java:40)
   at org.hibernate.ogm.query.impl.OgmQueryTranslator.getQuery(OgmQueryTranslator.java:168)
   at org.hibernate.ogm.query.impl.OgmQueryTranslator.getLoader(OgmQueryTranslator.java:130)
   at org.hibernate.ogm.query.impl.OgmQueryTranslator.list(OgmQueryTranslator.java:125)
   at org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:236)
   at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1264)
   at org.hibernate.internal.QueryImpl.list(QueryImpl.java:103)
   at org.hibernate.internal.AbstractQueryImpl.uniqueResult(AbstractQueryImpl.java:966)
   at opensocial.data.Message.hibernateCheckForDuplicates(Message.java:765)
   at opensocial.data.Message.hibernateStore(Message.java:712)
   at hibernate.HibernateStore.StoreCollection(HibernateStore.java:33)
   at request.manager.CollectionResultRequestManager.storeTmpResult(CollectionResultRequestManager.java:27)
   at request.manager.RequestManager.setStatus(RequestManager.java:30)
   at request.manager.GetMessagesRequestManager.searchSync(GetMessagesRequestManager.java:79)
   at request.manager.GetMessagesRequestManager.search(GetMessagesRequestManager.java:64)
   at request.endpoints.RestMessageService.searchInPlattforms(RestMessageService.java:92)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
   at java.lang.reflect.Method.invoke(Unknown Source)
   at com.sun.jersey.spi.container.JavaMethodInvokerFactory$1.invoke(JavaMethodInvokerFactory.java:60)
   at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$TypeOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:185)
   at com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75)
   at com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:302)
   at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
   at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108)
   at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
   at com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84)
   at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1542)
   at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1473)
   at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1419)
   at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1409)
   at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:409)
   at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:540)
   at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:715)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
   at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
   at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:503)
   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:136)
   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
   at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
   at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:526)
   at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1078)
   at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:655)
   at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:222)
   at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1566)
   at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1523)
   at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
   at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
   at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
   at java.lang.Thread.run(Unknown Source)


I know Mongo doesn't support JOIN-Operations, but which alternatives do i have? Maybe there is a smart solution.

Thx in advance and nice regards


Top
 Profile  
 
 Post subject: Re: Hibernate ORM to Hibernate OGM
PostPosted: Tue Jan 06, 2015 6:23 am 
Hibernate Team
Hibernate Team

Joined: Sat Jan 24, 2009 12:46 pm
Posts: 388
You'd have to decompose your query into several ones. First you'd fetch the ids of the relevant documents from the "joined" collection, then you'd select the referencing documents from the "joining" collection using the IN predicate "fetch from referencing_entity where referenced_id in (...)".

Hth,

--Gunnar

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


Top
 Profile  
 
 Post subject: Re: Hibernate ORM to Hibernate OGM
PostPosted: Wed Jan 07, 2015 3:49 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Note that at some point we want Hibernate OGM to give you help in that area. Maybe by decomposing the query and run all the queries for you when you set a hint that you know it has performance consequences. But in the mean time, we need you to do it by hand.

_________________
Emmanuel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 13 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.