Skip to content

Commit 26989d5

Browse files
committed
Initial Commit
1 parent b528e94 commit 26989d5

26 files changed

+1004
-0
lines changed

.classpath

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="src" output="target/classes" path="src/main/java">
4+
<attributes>
5+
<attribute name="optional" value="true"/>
6+
<attribute name="maven.pomderived" value="true"/>
7+
</attributes>
8+
</classpathentry>
9+
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
10+
<attributes>
11+
<attribute name="maven.pomderived" value="true"/>
12+
</attributes>
13+
</classpathentry>
14+
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
15+
<attributes>
16+
<attribute name="optional" value="true"/>
17+
<attribute name="maven.pomderived" value="true"/>
18+
<attribute name="test" value="true"/>
19+
</attributes>
20+
</classpathentry>
21+
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
22+
<attributes>
23+
<attribute name="maven.pomderived" value="true"/>
24+
<attribute name="test" value="true"/>
25+
</attributes>
26+
</classpathentry>
27+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5">
28+
<attributes>
29+
<attribute name="maven.pomderived" value="true"/>
30+
</attributes>
31+
</classpathentry>
32+
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
33+
<attributes>
34+
<attribute name="maven.pomderived" value="true"/>
35+
</attributes>
36+
</classpathentry>
37+
<classpathentry kind="src" path="target/generated-sources/annotations">
38+
<attributes>
39+
<attribute name="optional" value="true"/>
40+
<attribute name="maven.pomderived" value="true"/>
41+
<attribute name="ignore_optional_problems" value="true"/>
42+
<attribute name="m2e-apt" value="true"/>
43+
</attributes>
44+
</classpathentry>
45+
<classpathentry kind="src" output="target/test-classes" path="target/generated-test-sources/test-annotations">
46+
<attributes>
47+
<attribute name="optional" value="true"/>
48+
<attribute name="maven.pomderived" value="true"/>
49+
<attribute name="ignore_optional_problems" value="true"/>
50+
<attribute name="m2e-apt" value="true"/>
51+
<attribute name="test" value="true"/>
52+
</attributes>
53+
</classpathentry>
54+
<classpathentry kind="output" path="target/classes"/>
55+
</classpath>

.project

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>hibernate-entity-graph</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
<buildCommand>
14+
<name>org.eclipse.m2e.core.maven2Builder</name>
15+
<arguments>
16+
</arguments>
17+
</buildCommand>
18+
</buildSpec>
19+
<natures>
20+
<nature>org.eclipse.jdt.core.javanature</nature>
21+
<nature>org.eclipse.m2e.core.maven2Nature</nature>
22+
</natures>
23+
</projectDescription>
+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
eclipse.preferences.version=1
2+
org.eclipse.jdt.apt.aptEnabled=false

.settings/org.eclipse.jdt.core.prefs

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
eclipse.preferences.version=1
2+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
3+
org.eclipse.jdt.core.compiler.compliance=1.5
4+
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
5+
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
6+
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
7+
org.eclipse.jdt.core.compiler.processAnnotations=disabled
8+
org.eclipse.jdt.core.compiler.release=disabled
9+
org.eclipse.jdt.core.compiler.source=1.5

.settings/org.eclipse.m2e.core.prefs

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
activeProfiles=
2+
eclipse.preferences.version=1
3+
resolveWorkspaceProjects=true
4+
version=1

db/data.sql

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
INSERT INTO author (first_name, last_name, version) VALUES ('Joshua', 'Bloch', 0);
2+
INSERT INTO author (first_name, last_name, version) VALUES ('Gavin', 'King', 0);
3+
INSERT INTO author (first_name, last_name, version) VALUES ('Christian', 'Bauer', 0);
4+
INSERT INTO author (first_name, last_name, version) VALUES ('Gary', 'Gregory', 0);
5+
INSERT INTO author (first_name, last_name, version) VALUES ('Raoul-Gabriel', 'Urma', 0);
6+
INSERT INTO author (first_name, last_name, version) VALUES ('Mario', 'Fusco', 0);
7+
INSERT INTO author (first_name, last_name, version) VALUES ('Alan', 'Mycroft', 0);
8+
INSERT INTO author (first_name, last_name, version) VALUES ('Andrew Lee', 'Rubinger', 0);
9+
INSERT INTO author (first_name, last_name, version) VALUES ('Aslak', 'Knutsen', 0);
10+
INSERT INTO author (first_name, last_name, version) VALUES ('Bill', 'Burke', 0);
11+
INSERT INTO author (first_name, last_name, version) VALUES ('Scott', 'Oaks', 0);
12+
13+
INSERT INTO publisher (name, version) VALUES ('Addison-Wesley Professional', 0);
14+
INSERT INTO publisher (name, version) VALUES ('Manning Publications', 0);
15+
INSERT INTO publisher (name, version) VALUES ('OReilly Media, Inc', 0);
16+
17+
INSERT INTO book (publishing_date, title, version, publisher_id) VALUES ('2008-05-08', 'Effective Java', 0, 1);
18+
INSERT INTO book (publishing_date, title, version, publisher_id) VALUES ('2015-10-01', 'Java Persistence with Hibernate', 0, 2);
19+
INSERT INTO book (publishing_date, title, version, publisher_id) VALUES ('2014-08-28', 'Java 8 in Action', 0, 2);
20+
INSERT INTO book (publishing_date, title, version, publisher_id) VALUES ('2014-03-12', 'Continuous Enterprise Development in Java', 0, 3);
21+
INSERT INTO book (publishing_date, title, version, publisher_id) VALUES ('2010-09-08', 'Enterprise JavaBeans 3.1', 0, 3);
22+
INSERT INTO book (publishing_date, title, version, publisher_id) VALUES ('2014-04-29', 'Java Performance The Definitive Guide', 0, 3);
23+
24+
INSERT INTO book_author (book_id, author_id) VALUES (1, 1);
25+
INSERT INTO book_author (book_id, author_id) VALUES (2, 2);
26+
INSERT INTO book_author (book_id, author_id) VALUES (2, 3);
27+
INSERT INTO book_author (book_id, author_id) VALUES (2, 4);
28+
INSERT INTO book_author (book_id, author_id) VALUES (3, 5);
29+
INSERT INTO book_author (book_id, author_id) VALUES (3, 6);
30+
INSERT INTO book_author (book_id, author_id) VALUES (3, 7);
31+
INSERT INTO book_author (book_id, author_id) VALUES (4, 8);
32+
INSERT INTO book_author (book_id, author_id) VALUES (4, 9);
33+
INSERT INTO book_author (book_id, author_id) VALUES (5, 8);
34+
INSERT INTO book_author (book_id, author_id) VALUES (5, 10);
35+
INSERT INTO book_author (book_id, author_id) VALUES (6, 11);

pom.xml

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
2+
<modelVersion>4.0.0</modelVersion>
3+
<groupId>hibernate-entity-graph</groupId>
4+
<artifactId>hibernate-entity-graph</artifactId>
5+
<version>0.0.1-SNAPSHOT</version>
6+
<name>hibernate-entity-graph</name>
7+
8+
<dependencies>
9+
<dependency>
10+
<groupId>mysql</groupId>
11+
<artifactId>mysql-connector-java</artifactId>
12+
<version>8.0.20</version>
13+
</dependency>
14+
<dependency>
15+
<groupId>org.hibernate</groupId>
16+
<artifactId>hibernate-core</artifactId>
17+
<version>5.4.18.Final</version>
18+
</dependency>
19+
<!-- https://mvnrepository.com/artifact/javax.persistence/javax.persistence-api -->
20+
<dependency>
21+
<groupId>javax.persistence</groupId>
22+
<artifactId>javax.persistence-api</artifactId>
23+
<version>2.2</version>
24+
</dependency>
25+
26+
<dependency>
27+
<groupId>log4j</groupId>
28+
<artifactId>log4j</artifactId>
29+
<version>1.2.17</version>
30+
<scope>test</scope>
31+
</dependency>
32+
<dependency>
33+
<groupId>org.slf4j</groupId>
34+
<artifactId>slf4j-log4j12</artifactId>
35+
<version>1.7.30</version>
36+
<scope>test</scope>
37+
</dependency>
38+
39+
</dependencies>
40+
41+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
package com.tech.mkblogs.model;
2+
3+
import java.util.HashSet;
4+
import java.util.Set;
5+
6+
import javax.persistence.Column;
7+
import javax.persistence.Entity;
8+
import javax.persistence.FetchType;
9+
import javax.persistence.GeneratedValue;
10+
import javax.persistence.GenerationType;
11+
import javax.persistence.Id;
12+
import javax.persistence.ManyToMany;
13+
import javax.persistence.NamedAttributeNode;
14+
import javax.persistence.NamedEntityGraph;
15+
import javax.persistence.NamedSubgraph;
16+
import javax.persistence.Table;
17+
import javax.persistence.Version;
18+
19+
@Entity
20+
@Table(name = "author")
21+
@NamedEntityGraph(name = "graph.author.books.publisher",
22+
attributeNodes = @NamedAttributeNode(value = "books", subgraph = "books"),
23+
subgraphs = @NamedSubgraph(name = "books", attributeNodes = @NamedAttributeNode("publisher")) )
24+
25+
@NamedEntityGraph(name = "graph.author.books", attributeNodes = @NamedAttributeNode(value = "books"))
26+
27+
public class Author {
28+
29+
@Id
30+
@GeneratedValue(strategy = GenerationType.IDENTITY)
31+
private Integer id;
32+
33+
@Version
34+
private Integer version;
35+
36+
@Column(name = "first_name")
37+
private String firstName;
38+
39+
@Column(name = "last_name")
40+
private String lastName;
41+
42+
@ManyToMany(mappedBy="authors",fetch = FetchType.LAZY)
43+
private Set<Book> books = new HashSet<Book>();
44+
45+
public Integer getId() {
46+
return this.id;
47+
}
48+
49+
public Integer getVersion() {
50+
return this.version;
51+
}
52+
53+
public String getFirstName() {
54+
return firstName;
55+
}
56+
57+
public void setFirstName(String firstName) {
58+
this.firstName = firstName;
59+
}
60+
61+
public String getLastName() {
62+
return lastName;
63+
}
64+
65+
public void setLastName(String lastName) {
66+
this.lastName = lastName;
67+
}
68+
69+
public Set<Book> getBooks() {
70+
return this.books;
71+
}
72+
73+
public void setBooks(final Set<Book> books) {
74+
this.books = books;
75+
}
76+
77+
@Override
78+
public boolean equals(Object obj) {
79+
if (this == obj) {
80+
return true;
81+
}
82+
if (!(obj instanceof Author)) {
83+
return false;
84+
}
85+
Author other = (Author) obj;
86+
if (id != null) {
87+
if (!id.equals(other.id)) {
88+
return false;
89+
}
90+
}
91+
return true;
92+
}
93+
94+
@Override
95+
public int hashCode() {
96+
return 31;
97+
}
98+
99+
100+
@Override
101+
public String toString() {
102+
String result = getClass().getSimpleName() + " ";
103+
if (firstName != null && !firstName.trim().isEmpty())
104+
result += "firstName: " + firstName;
105+
if (lastName != null && !lastName.trim().isEmpty())
106+
result += ", lastName: " + lastName;
107+
return result;
108+
}
109+
}

0 commit comments

Comments
 (0)