Hibernate compares PersistentSet and HashSet


Antoine

I have a question. In my JUnit test, I want to test inserts in the database done by hibernate. I have an entity which has a list and I want to see if the inserted list is equal to the list I set.

assertEquals(listDerogationLinux, derogation.getListDerogationLinux());

The problem is that hibernate uses PersistentSet and I use HashMap, so when I try to compare them, I get AassertionError:

java.lang.AssertionError: expected: java.util.HashSet<[...]> but was: org.hibernate.collection.internal.PersistentSet<[...]>

I've tried many things, but the only thing that works is to create a new hashSet with the PersistentSet, but it's really ugly...

assertTrue(new HashSet<DerogationLinux>(derogation.getListDerogationLinux()).equals(listDerogationLinux));

Is there a better way?

Avseiytsev Dmitriy

Try calling equals on PersistentSet instead of HashSet. It should work.

persistentSet.equals(hashSet)

Related


Hibernate PersistentSet remove() operation not working

Chacko Mathew I have a collection in parent entity like this: Class Parent { @OneToMany(mappedBy = parent, cascade = CasacadeType.ALL) Set<Child> children; } Class Child { @Column(nullable=false) @ManyToOne Parent parent; } Now the event happens, if I d

Hibernate PersistentSet remove() operation not working

Chacko Mathew I have a collection in parent entity like this: Class Parent { @OneToMany(mappedBy = parent, cascade = CasacadeType.ALL) Set<Child> children; } Class Child { @Column(nullable=false) @ManyToOne Parent parent; } Now the event happens, if I d

Hibernate PersistentSet remove() operation not working

Chacko Mathew I have a collection in parent entity like this: Class Parent { @OneToMany(mappedBy = parent, cascade = CasacadeType.ALL) Set<Child> children; } Class Child { @Column(nullable=false) @ManyToOne Parent parent; } Now the event happens, if I d

Hibernate PersistentSet remove() operation not working

Chacko Mathew I have a collection in parent entity like this: Class Parent { @OneToMany(mappedBy = parent, cascade = CasacadeType.ALL) Set<Child> children; } Class Child { @Column(nullable=false) @ManyToOne Parent parent; } Now the event happens, if I d

HashSet in Hibernate

Kasik Subramani I have two POJO classes address and user_details. I need to know how the code works @ElementCollection private Set<Address>listOfAddresses = new HashSet(); public Set<Address> getListOfAddresses() { return listOfAddresses;

Hibernate query date compares months only

Arun Kumar S I need to grab some records from a MySQL table that has a column, posted_datethis is a Timestamp. I need to filter records by comparing with month only. For example, I only want all records to be published this month. I tried hibernate query date

Hibernate query date compares months only

Arunkumar S I need to grab some records from a MySQL table that has a column, posted_datethis is a Timestamp. I need to filter records by comparing with month only. For example, I only want all records to be published this month. I tried hibernate query date g

Hibernate query date compares months only

Arun Kumar S I need to grab some records from a MySQL table that has a column, posted_datethis is a Timestamp. I need to filter records by comparing with month only. For example, I only want all records to be published this month. I tried hibernate query date

Java: Update a hashset of a hashset

search In the example below, BigSetHashSet consists of HashSet SmallSet. I want to clear SmallSetwithout clearing BigSet. Instead, when I execute the command on clear(), SmallSetit is BigSetalso cleared. Why does this happen? How can I just clear SmallSetand l

HashSet as key of other HashSet

eggplant I am trying to use a HashSet<String>as a key for other keys HashSet. I found this question and answer pointing out the Hashtrait of the implementation HashSet<String>, but I can't make it work for my specific situation. Fortunately, my case is more co

How Java compares predicates

Nexussim elements: I have two predicates: Predicate<CategoryModel> predicate1 = NavigationCategoryModel.class::isInstance; Predicate<CategoryModel> predicate2 = BrandCategoryModel.class::isInstance; Using and if statement, how do I determine which predicate I

Compares an object to null!

fenec : I am trying to verify if an object is empty and I am using the following syntax: void renderSearch(Customer c){ System.out.println("search customer rendering>..."); try { if(!c.equals(null)){

How Java compares predicates

Nexussim elements: I have two predicates: Predicate<CategoryModel> predicate1 = NavigationCategoryModel.class::isInstance; Predicate<CategoryModel> predicate2 = BrandCategoryModel.class::isInstance; Using and if statement, how do I determine which predicate I

IEnumerable <XElement> compares differently

Vivek Shukla I read XML files by the following two techniques. By using Parse XElement to read the whole XML, XElement.Parse(File.ReadAllText(xmlfile))please note: I know I shouldn't use this technique. Loading by using XDocumentXDocument.Load(xmlfile); Then I

Query compares to empty fields

Daniele B : The documents in my Firestore collection have a string field which can be null . I expect if I query: Collection("products").Where("producedDate", "<", "2018-01-15") I will get all products with "producedDate" earlier than "2018-10-15", including

Compares an object to null!

fenec : I am trying to verify if an object is empty and I am using the following syntax: void renderSearch(Customer c){ System.out.println("search customer rendering>..."); try { if(!c.equals(null)){

Compares two buffers for equality

hr0min Is there a way to compare two buffers directly? For example, there are two identical files file1and file1-copy, I want to do this: f1 = open(file1) f2 = open(file1-copy) if f1 == f2 println("Equal content") end I know I can do string and compare t

Query compares to empty fields

Daniele B : The documents in my Firestore collection have a string field which can be null . I expect if I query: Collection("products").Where("producedDate", "<", "2018-01-15") I will get all products with "producedDate" earlier than "2018-10-15", including

Doctrine compares two objects

Wimut Hi I need to compare two objects in Doctrine. I have customer repository and entities. this is my code public function index(CarAdRepository $carAdRepository, CustomerRepository $customerRepository): Response { $cus = $customerRepository->findAl

Recursively compares the elements of a list with

mark61196: Hi update: thanks for all your suggestions Assuming this exercise is like a repetition exercise, I have a list of numbers made with the concepts of Cons and Nil, List l = new Cons(**3**, new Cons(**2**,new Cons(**1**, new Cons(**4**, new Cons(**1**,

zsh sed compares "\(" with "("

Mercutio I'm doing some string editing from a zsh script (on Mac OS Catalina). Some strings have a slash before the parentheses, some don't (usually a space). I'm trying to write a command that ignores opening parentheses unless it's preceded by a slash. So th

Compares two sequences for equality

HimBromBeere Before marking it as a duplicate due to the title, consider the following short procedure: static void Main() { var expected = new List<long[]> { new[] { Convert.ToInt64(1), Convert.ToInt64(999999) } }; var actual = DoSomething(); if (

array - compares int

Brady I'm having a problem with the code below, why I can't check "if(Person[i][0] < 18)" with an error stating "unparalleled type". I found articles that say I can use "if (Person[i][0].equals(18)), but how do I check if it's greater than? Object[][] Pers

A loop that compares the letters in a string

Hunter Gibson I'm trying to compare the letters and phrases of a user. I want it to go down every letter. I have a " if ((userGuessLength / phraseLength * 100.0) > 75.0)" as a placeholder and can only compare the length of the string, but need it to compare ea

Recursively compares the elements of a list with

mark61196: Hi update: thanks for all your suggestions Assuming this exercise is like a repetition exercise, I have a list of numbers made with the concepts of Cons and Nil, List l = new Cons(**3**, new Cons(**2**,new Cons(**1**, new Cons(**4**, new Cons(**1**,