这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions persistence-modules/hibernate-exceptions-2/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,16 @@
<artifactId>h2</artifactId>
<version>${h2.version}</version>
</dependency>
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<version>${hsqldb.version}</version>
</dependency>
</dependencies>

<properties>
<h2.version>2.3.232</h2.version>
<hsqldb.version>2.7.1</hsqldb.version>
</properties>

</project>
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.baeldung.hibernate.entitynotfoundexception;

import jakarta.persistence.*;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.baeldung.hibernate.entitynotfoundexception;

import jakarta.persistence.*;

import java.io.Serializable;

@Entity
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
package com.baeldung.hibernate.exception.persistentobject;

import java.util.Properties;

import com.baeldung.hibernate.exception.persistentobject.entity.Article;
import com.baeldung.hibernate.exception.persistentobject.entity.Author;
import com.baeldung.hibernate.exception.persistentobject.entity.Book;
import com.baeldung.hibernate.namedparameternotbound.Person;
import org.hibernate.SessionFactory;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment;
import org.hibernate.service.ServiceRegistry;

import com.baeldung.hibernate.exception.persistentobject.entity.Article;
import com.baeldung.hibernate.exception.persistentobject.entity.Author;
import com.baeldung.hibernate.exception.persistentobject.entity.Book;
import com.baeldung.hibernate.namedparameternotbound.Person;
import java.util.Properties;

public class HibernateUtil {
private static SessionFactory sessionFactory;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
package com.baeldung.hibernate.exception.persistentobject.entity;

import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.*;

@Entity
public class Article {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
package com.baeldung.hibernate.exception.persistentobject.entity;

import java.util.List;

import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.OneToMany;

import jakarta.persistence.*;
import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;

import java.util.List;

@Entity
public class Author {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
package com.baeldung.hibernate.exception.persistentobject.entity;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.*;

@Entity
public class Book {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package com.baeldung.hibernate.entitynotfoundexception;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import jakarta.persistence.EntityManager;
import jakarta.persistence.EntityManagerFactory;
import jakarta.persistence.EntityNotFoundException;
import jakarta.persistence.Persistence;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import java.io.IOException;

public class EntityNotFoundExceptionIntegrationTest {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
package com.baeldung.hibernate.exception.persistentobject;

import static java.util.Arrays.asList;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

import com.baeldung.hibernate.exception.persistentobject.entity.Article;
import com.baeldung.hibernate.exception.persistentobject.entity.Author;
import com.baeldung.hibernate.exception.persistentobject.entity.Book;
import org.hibernate.PropertyValueException;
import org.hibernate.Session;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import com.baeldung.hibernate.exception.persistentobject.entity.Article;
import com.baeldung.hibernate.exception.persistentobject.entity.Author;
import com.baeldung.hibernate.exception.persistentobject.entity.Book;
import static java.util.Arrays.asList;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

public class HibernatePersistentObjectUnitTest {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
package com.baeldung.hibernate.namedparameternotbound;

import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

import com.baeldung.hibernate.exception.persistentobject.HibernateUtil;
import org.hibernate.QueryException;
import org.hibernate.Session;
import org.hibernate.query.Query;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import com.baeldung.hibernate.exception.persistentobject.HibernateUtil;
import static org.junit.jupiter.api.Assertions.*;

class NamedParameterNotBoundExceptionUnitTest {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
package com.baeldung.hibernate.unknownentityexception;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

import com.baeldung.hibernate.exception.persistentobject.HibernateUtil;
import com.baeldung.hibernate.namedparameternotbound.Person;
import org.hibernate.Session;
import org.hibernate.query.Query;
import org.hibernate.query.sqm.UnknownEntityException;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import com.baeldung.hibernate.exception.persistentobject.HibernateUtil;
import com.baeldung.hibernate.namedparameternotbound.Person;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

class UnknownEntityExceptionUnitTest {

Expand All @@ -32,8 +31,8 @@ static void clear() {
@Test
void whenUsingUnknownEntity_thenThrowUnknownEntityException() {
assertThatThrownBy(() -> session.createQuery("FROM PERSON", Person.class))
.hasRootCauseInstanceOf(UnknownEntityException.class)
.hasRootCauseMessage("Could not resolve root entity 'PERSON'");
.hasRootCauseInstanceOf(UnknownEntityException.class)
.hasRootCauseMessage("Could not resolve root entity 'PERSON'");
}

@Test
Expand Down