Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7750065
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T11:11:37+00:00 2026-06-01T11:11:37+00:00

I am clustering tweets based on a search from Twitter and trying to store

  • 0

I am clustering tweets based on a search from Twitter and trying to store the results in a database using Hibernate in Java. When I try to save the SearchResults object, I get an error like the following:

org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session

What do I need to do so that both the TweetCluster.java and the SearchResults.java can point to the same table of Tweets in the database? I could change TweetCluster.java so it points to a separate table which stores the tweets again, but that seems like a waste of space.

I’ve pulled out the important code as shown below.

@Entity
@Table(name="search_results")
public class SearchResults {

  @Id
  @GeneratedValue(strategy=GenerationType.IDENTITY)
  private long searchId;

  @ManyToMany(targetEntity = Tweet.class, cascade=CascadeType.ALL, fetch=FetchType.EAGER)
  @OrderColumn(name="orderIndex")
  private List<Tweet> tweets;

  @OneToMany(targetEntity = TweetCluster.class, cascade=CascadeType.ALL, fetch=FetchType.EAGER, orphanRemoval=true)
  @OrderColumn(name="orderIndex")
  private List<TweetCluster> clusters;

  public SearchResults() {
    tweets = new ArrayList<Tweet>();
    clusters = new ArrayList<TweetCluster>();
  }

  public List<Tweet> getTweets() {
    return tweets;
  }

  public void addTweet(Tweet tweet){
    tweets.add(tweet);
  }


  public void addCluster(TweetCluster cluster){
    clusters.add(cluster);
  }

  public List<TweetCluster> getClusters() {
    return clusters;
  }

}


@Entity
@Table(name="tweet_cluster")
public class TweetCluster {

  @Id
  @GeneratedValue(strategy=GenerationType.IDENTITY)
  private long id;
  private String name;

  @ManyToMany(targetEntity = Tweet.class, fetch=FetchType.EAGER)
  @OrderColumn(name="orderIndex")
  private List<Tweet> tweets;

  public TweetCluster(){
    tweets = new ArrayList<Tweet>();
  }

  public TweetCluster(String name){
    this();
    this.name=name;
  }

  public long getId(){
     return id;
  }

  public void setId(long id){
    this.id = id;
  }

  public List<Tweet> getTweets() {
    return tweets;
  }

  public void addTweet(Tweet tweet){
    tweets.add(tweet);
  }

}


@Entity
@Table(name="tweet")
public class Tweet {

  @Id
  @GenericGenerator(name="assigned", strategy = "assigned")
  private long tweetId;

  private String text;

  public Tweet(){

  }

  public long getTweetId() {
    return tweetId;
  }

  public void setTweetId(long id){
    this.tweetId = id;
  }

  public String getText() {
    return text;
  }

  public void setText(String text) {
    this.text = text;
  }

}

EDIT:

To save the results, I run code something like the following:

SearchResults searchResult = new SearchResults();
searchResult .addCluster(new TweetCluster("cluster1"));
searchResult .addCluster(new TweetCluster("cluster2"));

searchResult.addTweet(new Tweet("Tweet 1"));
searchResult.addTweet(new Tweet("Tweet 2"));
searchResult.addTweet(new Tweet("Tweet 3"));
session.saveOrUpdate(searchResult);

The exception gets thrown at saveOrUpdate

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T11:11:38+00:00Added an answer on June 1, 2026 at 11:11 am

    It turns out the problem was really simple. The generator for Tweet is assigned. In my unit test I forgot to assign an id. Thus several tweets had an id of zero.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In order to perform a simple clustering algorithm on results that I get from
I'm trying to perform a hierarchical clustering using a custom distance measure. I perform
I want to implement my own clustering algorithm using this Virtual Earth javascript API:
I am using gmap3 script to show clustering markers, but i have some questions
I am trying to test the likelihood that a particular clustering of data has
while profiling a java application that calculates hierarchical clustering of thousands of elements I
I'm trying to play around with some music clustering algorithms, and I thought that
I am planning an application which will make clusters of short messages/tweets based on
I'm using the clustering technique given here for clustering a large dataset, which is
My programme uses K-means clustering of a set amount of clusters from the user.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.