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 <link rel="type" .../>
*/
@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 <link rel="type" .../>
*/
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 <link rel="type" .../>
*/
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 <link rel="type" .../>
*/
@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 <link rel="type" .../>
*/
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 <link rel="type" .../>
*/
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 <link rel="type" .../>
*/
@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 <link rel="type" .../>
*/
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 <link rel="type" .../>
*/
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 <link rel="type" .../>
*/
@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 <link rel="type" .../>
*/
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 <link rel="type" .../>
*/
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