kandi background
kandi background
Explore Kits
kandi background
Explore Kits
Explore all Hibernate open source software, libraries, packages, source code, cloud functions and APIs.

Popular New Releases in Hibernate

dropwizard

v3.0.0-beta.2

querydsl

5.0.0

jetcache

liquibase

v4.9.1

speedment

3.2.10

dropwizard

v3.0.0-beta.2

querydsl

5.0.0

jetcache

liquibase

v4.9.1

speedment

3.2.10

Popular Libraries in Hibernate

dropwizard

by dropwizard java

star image 8161 Apache-2.0

A damn simple library for building production-ready RESTful web services.

jeesite

by thinkgem javascript

star image 7653 Apache-2.0

JeeSite 是一个企业信息化开发基础平台,Java企业应用开源框架,Java EE(J2EE)快速开发框架,使用经典技术组合(Spring、Spring MVC、Apache Shiro、MyBatis、Bootstrap UI),包括核心模块如:组织机构、角色用户、权限授权、数据权限、内容管理、工作流等。

tomcat

by apache java

star image 5943 Apache-2.0

Apache Tomcat

hibernate-orm

by hibernate java

star image 4916

Hibernate's core Object/Relational Mapping functionality

jOOQ

by jOOQ java

star image 4882 NOASSERTION

jOOQ is the best way to write SQL in Java

favorites-web

by cloudfavorites html

star image 4376

云收藏 Spring Boot 2.X 开源项目

shopping-management-system

by zhanglei-workspace java

star image 3965

该项目为多个小项目的集合(持续更新中...)。内容类似淘宝、京东等网购管理系统以及图书管理、超市管理等系统。目的在于便于Java初级爱好者在学习完某一部分Java知识后有一个合适的项目锻炼、运用所学知识,完善知识体系。适用人群:Java基础到入门的爱好者。

querydsl

by querydsl java

star image 3754 Apache-2.0

Unified Queries for Java

java-learning

by brianway java

star image 3687

旨在打造在线最佳的 Java 学习笔记,含博客讲解和源码实例,包括 Java SE 和 Java Web

dropwizard

by dropwizard java

star image 8161 Apache-2.0

A damn simple library for building production-ready RESTful web services.

jeesite

by thinkgem javascript

star image 7653 Apache-2.0

JeeSite 是一个企业信息化开发基础平台,Java企业应用开源框架,Java EE(J2EE)快速开发框架,使用经典技术组合(Spring、Spring MVC、Apache Shiro、MyBatis、Bootstrap UI),包括核心模块如:组织机构、角色用户、权限授权、数据权限、内容管理、工作流等。

tomcat

by apache java

star image 5943 Apache-2.0

Apache Tomcat

hibernate-orm

by hibernate java

star image 4916

Hibernate's core Object/Relational Mapping functionality

jOOQ

by jOOQ java

star image 4882 NOASSERTION

jOOQ is the best way to write SQL in Java

favorites-web

by cloudfavorites html

star image 4376

云收藏 Spring Boot 2.X 开源项目

shopping-management-system

by zhanglei-workspace java

star image 3965

该项目为多个小项目的集合(持续更新中...)。内容类似淘宝、京东等网购管理系统以及图书管理、超市管理等系统。目的在于便于Java初级爱好者在学习完某一部分Java知识后有一个合适的项目锻炼、运用所学知识,完善知识体系。适用人群:Java基础到入门的爱好者。

querydsl

by querydsl java

star image 3754 Apache-2.0

Unified Queries for Java

java-learning

by brianway java

star image 3687

旨在打造在线最佳的 Java 学习笔记,含博客讲解和源码实例,包括 Java SE 和 Java Web

Trending New libraries in Hibernate

AgileTC

by didi java

star image 430 NOASSERTION

AgileTC is an agile test case management platform

flink-boot

by intsmaze java

star image 282 BSD-3-Clause

懒松鼠Flink-Boot 脚手架让Flink全面拥抱Spring生态体系,使得开发者可以以Java WEB开发模式开发出分布式运行的流处理程序,懒松鼠让跨界变得更加简单。懒松鼠旨在让开发者以更底上手成本(不需要理解分布式计算的理论知识和Flink框架的细节)便可以快速编写业务代码实现。为了进一步提升开发者使用懒松鼠脚手架开发大型项目的敏捷的度,该脚手架默认集成Spring框架进行Bean管理,同时将微服务以及WEB开发领域中经常用到的框架集成进来,进一步提升开发速度。比如集成Mybatis ORM框架,Hibernate Validator校验框架,Spring Retry重试框架等,具体见下面的脚手架特性。

ReactJS-Spring-Boot-CRUD-Full-Stack-App

by RameshMF javascript

star image 235

Learn how to develop a full-stack CRUD application using React as frontend and spring boot as backend.

spring-data-jpa-course

by amigoscode java

star image 201

JavaCollege

by xzyJavaX java

star image 178

开源项目+个人博客

yaoqishan

by user-xiangpeng java

star image 177

妖气山视频管理系统-mysql版

o365

by vanyouseea css

star image 159 MIT

O365管理系统是一个以java语言开发的基于Microsoft Graph Restful API的多全局管理系统,理论上支持任何Office全局的管理(A1,A3,A1P,E3,E5等),你可以很方便的使用它来批量添加,批量删除,批量启用,批量禁用,搜索和查看用户,生成邀请码,邀请朋友注册,提升和收回管理员权限,更新密钥,查看订阅,分配订阅(创新用户时),查看多全局报告

SpringBoot-Projects-FullStack

by Urunov javascript

star image 147

Spring Boot, JDBC, ORM, JPA, Hibernate, H2, MySQL, Oracle

sims

by rawchen java

star image 112

学生信息管理系统SIMS,Java Servlet And Jsp.

AgileTC

by didi java

star image 430 NOASSERTION

AgileTC is an agile test case management platform

flink-boot

by intsmaze java

star image 282 BSD-3-Clause

懒松鼠Flink-Boot 脚手架让Flink全面拥抱Spring生态体系,使得开发者可以以Java WEB开发模式开发出分布式运行的流处理程序,懒松鼠让跨界变得更加简单。懒松鼠旨在让开发者以更底上手成本(不需要理解分布式计算的理论知识和Flink框架的细节)便可以快速编写业务代码实现。为了进一步提升开发者使用懒松鼠脚手架开发大型项目的敏捷的度,该脚手架默认集成Spring框架进行Bean管理,同时将微服务以及WEB开发领域中经常用到的框架集成进来,进一步提升开发速度。比如集成Mybatis ORM框架,Hibernate Validator校验框架,Spring Retry重试框架等,具体见下面的脚手架特性。

ReactJS-Spring-Boot-CRUD-Full-Stack-App

by RameshMF javascript

star image 235

Learn how to develop a full-stack CRUD application using React as frontend and spring boot as backend.

spring-data-jpa-course

by amigoscode java

star image 201

JavaCollege

by xzyJavaX java

star image 178

开源项目+个人博客

yaoqishan

by user-xiangpeng java

star image 177

妖气山视频管理系统-mysql版

o365

by vanyouseea css

star image 159 MIT

O365管理系统是一个以java语言开发的基于Microsoft Graph Restful API的多全局管理系统,理论上支持任何Office全局的管理(A1,A3,A1P,E3,E5等),你可以很方便的使用它来批量添加,批量删除,批量启用,批量禁用,搜索和查看用户,生成邀请码,邀请朋友注册,提升和收回管理员权限,更新密钥,查看订阅,分配订阅(创新用户时),查看多全局报告

SpringBoot-Projects-FullStack

by Urunov javascript

star image 147

Spring Boot, JDBC, ORM, JPA, Hibernate, H2, MySQL, Oracle

sims

by rawchen java

star image 112

学生信息管理系统SIMS,Java Servlet And Jsp.

Top Authors in Hibernate

1

RameshMF

26 Libraries

1051

2

hibernate

16 Libraries

7583

3

hendisantika

15 Libraries

96

4

pratikdimble

15 Libraries

41

5

scbushan05

12 Libraries

112

6

loiane

9 Libraries

99

7

kousen

9 Libraries

701

8

hantsy

9 Libraries

779

9

hellokoding

8 Libraries

228

10

datanucleus

8 Libraries

67

1

26 Libraries

1051

2

16 Libraries

7583

3

15 Libraries

96

4

15 Libraries

41

5

12 Libraries

112

6

9 Libraries

99

7

9 Libraries

701

8

9 Libraries

779

9

8 Libraries

228

10

8 Libraries

67

Trending Kits in Hibernate

No Trending Kits are available at this moment for Hibernate

Trending Discussions on Hibernate

    Java @Override equals(): When this.getClass() != o.getClass() fails but shouldn't
    Hibernate JOIN [some entity] ON unexpected token
    Does hibernate set back reference in @OneToMany @ManyToOne relationship automatically?
    Java 17: Maven doesn't give much information about the error that happened, why?
    What should I replace the hibernate deprecated @TypeDef and @Type annotations by?
    JDBC with H2 and MySQL mode: create procedure fails
    Hibernate Interceptor not working after upgrading to Hibernate 5
    Spring boot applicaiton unable to find SQLite jdbc driver class
    Log4j2 deadlock
    Invalid DateTimeFormat when inserting date in H2 in memory DB

QUESTION

Java @Override equals(): When this.getClass() != o.getClass() fails but shouldn't

Asked 2022-Apr-17 at 12:25

I have this @Override for equals() in my MyClass class:

1public class MyClass extends MySuperClass
2{
3  ...
4  @Override
5  public boolean equals( Object o )
6  {
7    if ( this == o )
8    {
9      return true;
10    }
11    if ( o == null || this.getClass() != o.getClass() )
12    {
13      return false;
14    }
15    if ( !super.equals( o ) )
16    {
17      return false;
18    }
19    MyClass that = ( MyClass ) o;
20    return this.var1.equals( that.var1 ) && this.var2.equals( that.var2 );
21  }
22  ...
23}
24

Pretty standard. Matter of fact, it follows Java best practices.
Later in life I have this in another sub-package class (my controller class):

1public class MyClass extends MySuperClass
2{
3  ...
4  @Override
5  public boolean equals( Object o )
6  {
7    if ( this == o )
8    {
9      return true;
10    }
11    if ( o == null || this.getClass() != o.getClass() )
12    {
13      return false;
14    }
15    if ( !super.equals( o ) )
16    {
17      return false;
18    }
19    MyClass that = ( MyClass ) o;
20    return this.var1.equals( that.var1 ) && this.var2.equals( that.var2 );
21  }
22  ...
23}
24...
25package com.a.b.api.controllers;
26...
27import com.a.b.jpa.models.MyClass;
28...
29MyClass myObject1 = new MyClass( var1, var2 );
30MyClass myObject2 = this.myClassRepository.getById( 1 ); // SpringBoot/Jpa/Hibernate
31
32if ( myObject2.equals( myObject1 ) )
33{
34   ...do something...
35}
36...
37this.myClassRepository.save( myObject1 );
38...
39

My problem is that the .equals() is always failing here:

1public class MyClass extends MySuperClass
2{
3  ...
4  @Override
5  public boolean equals( Object o )
6  {
7    if ( this == o )
8    {
9      return true;
10    }
11    if ( o == null || this.getClass() != o.getClass() )
12    {
13      return false;
14    }
15    if ( !super.equals( o ) )
16    {
17      return false;
18    }
19    MyClass that = ( MyClass ) o;
20    return this.var1.equals( that.var1 ) && this.var2.equals( that.var2 );
21  }
22  ...
23}
24...
25package com.a.b.api.controllers;
26...
27import com.a.b.jpa.models.MyClass;
28...
29MyClass myObject1 = new MyClass( var1, var2 );
30MyClass myObject2 = this.myClassRepository.getById( 1 ); // SpringBoot/Jpa/Hibernate
31
32if ( myObject2.equals( myObject1 ) )
33{
34   ...do something...
35}
36...
37this.myClassRepository.save( myObject1 );
38...
39if ( o == null || this.getClass() != o.getClass() )
40

because java says that this.getClass() and o.getClass() are NOT equal. When I debug the code (in Intellij IDEA 2022.1 UE) I see this:

this.getClass() = MyClass@13706

but

o.getClass = com.a.b.jpa.models.MyClass@8f7462

But they are the same class! Almost every Java book, tutorial, blog, Intellij IDEA, etc. demonstrates the .equals() this way. I have tried this in Ubuntu 20.04.4 LTS java-14-openjdk-amd64 and java-17-openjdk-amd64 with the same results.

What am I doing wrong?

ANSWER

Answered 2022-Apr-14 at 15:31

myObject2 is an instance of a proxy class, generated at runtime by Hibernate using Byte Buddy. The generated proxy intercepts all method invocations, that's why getClass() returns different results.

As an alternative to getClass(), using instanceof might be another approach:

1public class MyClass extends MySuperClass
2{
3  ...
4  @Override
5  public boolean equals( Object o )
6  {
7    if ( this == o )
8    {
9      return true;
10    }
11    if ( o == null || this.getClass() != o.getClass() )
12    {
13      return false;
14    }
15    if ( !super.equals( o ) )
16    {
17      return false;
18    }
19    MyClass that = ( MyClass ) o;
20    return this.var1.equals( that.var1 ) && this.var2.equals( that.var2 );
21  }
22  ...
23}
24...
25package com.a.b.api.controllers;
26...
27import com.a.b.jpa.models.MyClass;
28...
29MyClass myObject1 = new MyClass( var1, var2 );
30MyClass myObject2 = this.myClassRepository.getById( 1 ); // SpringBoot/Jpa/Hibernate
31
32if ( myObject2.equals( myObject1 ) )
33{
34   ...do something...
35}
36...
37this.myClassRepository.save( myObject1 );
38...
39if ( o == null || this.getClass() != o.getClass() )
40if ( !(this instanceof MyClass && o instanceof MyClass) )
41{
42   return false;
43}
44

However keep in mind that instanceof has its drawbacks. It violates the symmetry principle.

You shouldn't compare these objects in the first place, since a new object should be different from a Hibernate managed one that has a persistent state.

Source https://stackoverflow.com/questions/71873676

Community Discussions contain sources that include Stack Exchange Network

    Java @Override equals(): When this.getClass() != o.getClass() fails but shouldn't
    Hibernate JOIN [some entity] ON unexpected token
    Does hibernate set back reference in @OneToMany @ManyToOne relationship automatically?
    Java 17: Maven doesn't give much information about the error that happened, why?
    What should I replace the hibernate deprecated @TypeDef and @Type annotations by?
    JDBC with H2 and MySQL mode: create procedure fails
    Hibernate Interceptor not working after upgrading to Hibernate 5
    Spring boot applicaiton unable to find SQLite jdbc driver class
    Log4j2 deadlock
    Invalid DateTimeFormat when inserting date in H2 in memory DB

QUESTION

Java @Override equals(): When this.getClass() != o.getClass() fails but shouldn't

Asked 2022-Apr-17 at 12:25

I have this @Override for equals() in my MyClass class:

1public class MyClass extends MySuperClass
2{
3  ...
4  @Override
5  public boolean equals( Object o )
6  {
7    if ( this == o )
8    {
9      return true;
10    }
11    if ( o == null || this.getClass() != o.getClass() )
12    {
13      return false;
14    }
15    if ( !super.equals( o ) )
16    {
17      return false;
18    }
19    MyClass that = ( MyClass ) o;
20    return this.var1.equals( that.var1 ) && this.var2.equals( that.var2 );
21  }
22  ...
23}
24

Pretty standard. Matter of fact, it follows Java best practices.
Later in life I have this in another sub-package class (my controller class):

1public class MyClass extends MySuperClass
2{
3  ...
4  @Override
5  public boolean equals( Object o )
6  {
7    if ( this == o )
8    {
9      return true;
10    }
11    if ( o == null || this.getClass() != o.getClass() )
12    {
13      return false;
14    }
15    if ( !super.equals( o ) )
16    {
17      return false;
18    }
19    MyClass that = ( MyClass ) o;
20    return this.var1.equals( that.var1 ) && this.var2.equals( that.var2 );
21  }
22  ...
23}
24...
25package com.a.b.api.controllers;
26...
27import com.a.b.jpa.models.MyClass;
28...
29MyClass myObject1 = new MyClass( var1, var2 );
30MyClass myObject2 = this.myClassRepository.getById( 1 ); // SpringBoot/Jpa/Hibernate
31
32if ( myObject2.equals( myObject1 ) )
33{
34   ...do something...
35}
36...
37this.myClassRepository.save( myObject1 );
38...
39

My problem is that the .equals() is always failing here:

1public class MyClass extends MySuperClass
2{
3  ...
4  @Override
5  public boolean equals( Object o )
6  {
7    if ( this == o )
8    {
9      return true;
10    }
11    if ( o == null || this.getClass() != o.getClass() )
12    {
13      return false;
14    }
15    if ( !super.equals( o ) )
16    {
17      return false;
18    }
19    MyClass that = ( MyClass ) o;
20    return this.var1.equals( that.var1 ) && this.var2.equals( that.var2 );
21  }
22  ...
23}
24...
25package com.a.b.api.controllers;
26...
27import com.a.b.jpa.models.MyClass;
28...
29MyClass myObject1 = new MyClass( var1, var2 );
30MyClass myObject2 = this.myClassRepository.getById( 1 ); // SpringBoot/Jpa/Hibernate
31
32if ( myObject2.equals( myObject1 ) )
33{
34   ...do something...
35}
36...
37this.myClassRepository.save( myObject1 );
38...
39if ( o == null || this.getClass() != o.getClass() )
40

because java says that this.getClass() and o.getClass() are NOT equal. When I debug the code (in Intellij IDEA 2022.1 UE) I see this:

this.getClass() = MyClass@13706

but

o.getClass = com.a.b.jpa.models.MyClass@8f7462

But they are the same class! Almost every Java book, tutorial, blog, Intellij IDEA, etc. demonstrates the .equals() this way. I have tried this in Ubuntu 20.04.4 LTS java-14-openjdk-amd64 and java-17-openjdk-amd64 with the same results.

What am I doing wrong?

ANSWER

Answered 2022-Apr-14 at 15:31

myObject2 is an instance of a proxy class, generated at runtime by Hibernate using Byte Buddy. The generated proxy intercepts all method invocations, that's why getClass() returns different results.

As an alternative to getClass(), using instanceof might be another approach:

1public class MyClass extends MySuperClass
2{
3  ...
4  @Override
5  public boolean equals( Object o )
6  {
7    if ( this == o )
8    {
9      return true;
10    }
11    if ( o == null || this.getClass() != o.getClass() )
12    {
13      return false;
14    }
15    if ( !super.equals( o ) )
16    {
17      return false;
18    }
19    MyClass that = ( MyClass ) o;
20    return this.var1.equals( that.var1 ) && this.var2.equals( that.var2 );
21  }
22  ...
23}
24...
25package com.a.b.api.controllers;
26...
27import com.a.b.jpa.models.MyClass;
28...
29MyClass myObject1 = new MyClass( var1, var2 );
30MyClass myObject2 = this.myClassRepository.getById( 1 ); // SpringBoot/Jpa/Hibernate
31
32if ( myObject2.equals( myObject1 ) )
33{
34   ...do something...
35}
36...
37this.myClassRepository.save( myObject1 );
38...
39if ( o == null || this.getClass() != o.getClass() )
40if ( !(this instanceof MyClass && o instanceof MyClass) )
41{
42   return false;
43}
44

However keep in mind that instanceof has its drawbacks. It violates the symmetry principle.

You shouldn't compare these objects in the first place, since a new object should be different from a Hibernate managed one that has a persistent state.

Source https://stackoverflow.com/questions/71873676