-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cf41449
commit e57ec99
Showing
18 changed files
with
547 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<classpath> | ||
<classpathentry kind="src" output="target/classes" path="src/main/java"> | ||
<attributes> | ||
<attribute name="optional" value="true"/> | ||
<attribute name="maven.pomderived" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"> | ||
<attributes> | ||
<attribute name="maven.pomderived" value="true"/> | ||
<attribute name="optional" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="src" output="target/test-classes" path="src/test/java"> | ||
<attributes> | ||
<attribute name="optional" value="true"/> | ||
<attribute name="maven.pomderived" value="true"/> | ||
<attribute name="test" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources"> | ||
<attributes> | ||
<attribute name="maven.pomderived" value="true"/> | ||
<attribute name="test" value="true"/> | ||
<attribute name="optional" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"> | ||
<attributes> | ||
<attribute name="maven.pomderived" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"> | ||
<attributes> | ||
<attribute name="maven.pomderived" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="output" path="target/classes"/> | ||
</classpath> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/target/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>ExampleApp</name> | ||
<comment></comment> | ||
<projects> | ||
</projects> | ||
<buildSpec> | ||
<buildCommand> | ||
<name>org.eclipse.jdt.core.javabuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
<buildCommand> | ||
<name>org.eclipse.m2e.core.maven2Builder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
</buildSpec> | ||
<natures> | ||
<nature>org.eclipse.jdt.core.javanature</nature> | ||
<nature>org.eclipse.m2e.core.maven2Nature</nature> | ||
</natures> | ||
</projectDescription> |
4 changes: 4 additions & 0 deletions
4
mapping/association-mapping/ExampleApp/.settings/org.eclipse.core.resources.prefs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
eclipse.preferences.version=1 | ||
encoding//src/main/java=UTF-8 | ||
encoding//src/test/java=UTF-8 | ||
encoding/<project>=UTF-8 |
8 changes: 8 additions & 0 deletions
8
mapping/association-mapping/ExampleApp/.settings/org.eclipse.jdt.core.prefs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
eclipse.preferences.version=1 | ||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 | ||
org.eclipse.jdt.core.compiler.compliance=1.8 | ||
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled | ||
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning | ||
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore | ||
org.eclipse.jdt.core.compiler.release=disabled | ||
org.eclipse.jdt.core.compiler.source=1.8 |
4 changes: 4 additions & 0 deletions
4
mapping/association-mapping/ExampleApp/.settings/org.eclipse.m2e.core.prefs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
activeProfiles= | ||
eclipse.preferences.version=1 | ||
resolveWorkspaceProjects=true | ||
version=1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>com.giriharan</groupId> | ||
<artifactId>ExampleApp</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
<packaging>jar</packaging> | ||
|
||
<name>ExampleApp</name> | ||
<url>http://maven.apache.org</url> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>3.8.1</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-core --> | ||
<dependency> | ||
<groupId>org.hibernate</groupId> | ||
<artifactId>hibernate-core</artifactId> | ||
<version>5.6.15.Final</version> | ||
</dependency> | ||
|
||
<!-- https://mvnrepository.com/artifact/com.mysql/mysql-connector-j --> | ||
<dependency> | ||
<groupId>com.mysql</groupId> | ||
<artifactId>mysql-connector-j</artifactId> | ||
<version>8.2.0</version> | ||
</dependency> | ||
|
||
|
||
</dependencies> | ||
</project> |
47 changes: 47 additions & 0 deletions
47
mapping/association-mapping/ExampleApp/src/main/java/com/giriharan/ExampleApp/AppMTM.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package com.giriharan.ExampleApp; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.hibernate.Session; | ||
import org.hibernate.SessionFactory; | ||
import org.hibernate.Transaction; | ||
import org.hibernate.cfg.Configuration; | ||
|
||
public class AppMTM { | ||
public static void main(String[] args) { | ||
Configuration cfg = new Configuration().configure("hibernate.cfg.xml").addAnnotatedClass(Customer.class).addAnnotatedClass(Product.class); | ||
SessionFactory sf = cfg.buildSessionFactory(); | ||
|
||
Session session = sf.openSession(); | ||
Transaction transaction = session.beginTransaction(); | ||
|
||
Customer customer1 = new Customer(); | ||
List<Customer> customers = new ArrayList<>(); | ||
customers.add(customer1); | ||
|
||
Product product1 = new Product(); | ||
Product product2 = new Product(); | ||
List<Product> products = new ArrayList<>(); | ||
product1.setCustomers(customers); | ||
product2.setCustomers(customers); | ||
customer1.setProducts(products); | ||
products.add(product1); | ||
products.add(product2); | ||
|
||
/* Before cascading | ||
session.save(customer1); | ||
session.save(product1); | ||
session.save(product2); */ | ||
|
||
// After cascading | ||
session.save(customer1); | ||
|
||
|
||
transaction.commit(); | ||
session.close(); | ||
|
||
System.out.println("Successfully added!"); | ||
} | ||
|
||
} |
41 changes: 41 additions & 0 deletions
41
...ing/association-mapping/ExampleApp/src/main/java/com/giriharan/ExampleApp/AppOTM_MTO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.giriharan.ExampleApp; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.hibernate.Session; | ||
import org.hibernate.SessionFactory; | ||
import org.hibernate.Transaction; | ||
import org.hibernate.cfg.Configuration; | ||
|
||
public class AppOTM_MTO { | ||
public static void main(String args[]) { | ||
Configuration cfg = new Configuration().configure("hibernate.cfg.xml").addAnnotatedClass(Library.class).addAnnotatedClass(Book.class); | ||
SessionFactory sf = cfg.buildSessionFactory(); | ||
|
||
Session session = sf.openSession(); | ||
Transaction transaction = session.beginTransaction(); | ||
|
||
Library library = new Library(); | ||
Book book1 = new Book("God of war : Ragnarok"); | ||
Book book2 = new Book("Red Dead Redemption II"); | ||
book1.setLibrary(library); | ||
book2.setLibrary(library); | ||
|
||
List<Book> books = new ArrayList<Book>(); | ||
books.add(book1); | ||
books.add(book2); | ||
|
||
library.setBooks(books); | ||
|
||
session.save(book1); | ||
session.save(book2); | ||
session.save(library); | ||
|
||
transaction.commit(); | ||
session.close(); | ||
|
||
System.out.println("Successfully added!"); | ||
} | ||
|
||
} |
33 changes: 33 additions & 0 deletions
33
mapping/association-mapping/ExampleApp/src/main/java/com/giriharan/ExampleApp/AppOTO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.giriharan.ExampleApp; | ||
|
||
import org.hibernate.Session; | ||
import org.hibernate.SessionFactory; | ||
import org.hibernate.Transaction; | ||
import org.hibernate.cfg.Configuration; | ||
|
||
public class AppOTO | ||
{ | ||
public static void main( String[] args ) | ||
{ | ||
Configuration cfg = new Configuration().configure("hibernate.cfg.xml").addAnnotatedClass(Person.class).addAnnotatedClass(Passport.class); | ||
SessionFactory sf = cfg.buildSessionFactory(); | ||
|
||
Session session = sf.openSession(); | ||
Transaction transaction = session.beginTransaction(); | ||
|
||
|
||
Person person = new Person("Arjun"); | ||
Passport passport = new Passport(); | ||
person.setPassport(passport); | ||
passport.setPerson(person); | ||
|
||
session.save(person); | ||
session.save(passport); | ||
|
||
transaction.commit(); | ||
session.close(); | ||
|
||
System.out.println("Successfully added!"); | ||
|
||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
mapping/association-mapping/ExampleApp/src/main/java/com/giriharan/ExampleApp/Book.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package com.giriharan.ExampleApp; | ||
|
||
import javax.persistence.Column; | ||
import javax.persistence.Entity; | ||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.GenerationType; | ||
import javax.persistence.Id; | ||
import javax.persistence.ManyToOne; | ||
|
||
@Entity | ||
public class Book { | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.AUTO) | ||
private int id; | ||
|
||
@Column(name="name") | ||
private String name; | ||
|
||
@ManyToOne | ||
private Library library; | ||
|
||
public Book(String name) { | ||
super(); | ||
this.name = name; | ||
} | ||
|
||
public int getId() { | ||
return id; | ||
} | ||
|
||
public void setId(int id) { | ||
this.id = id; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public Library getLibrary() { | ||
return library; | ||
} | ||
|
||
public void setLibrary(Library library) { | ||
this.library = library; | ||
} | ||
|
||
|
||
} |
42 changes: 42 additions & 0 deletions
42
mapping/association-mapping/ExampleApp/src/main/java/com/giriharan/ExampleApp/Customer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package com.giriharan.ExampleApp; | ||
|
||
import java.util.List; | ||
|
||
import javax.persistence.CascadeType; | ||
import javax.persistence.Entity; | ||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.GenerationType; | ||
import javax.persistence.Id; | ||
import javax.persistence.JoinColumn; | ||
import javax.persistence.JoinTable; | ||
import javax.persistence.ManyToMany; | ||
|
||
|
||
@Entity | ||
public class Customer { | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.AUTO) | ||
private int id; | ||
|
||
@ManyToMany(cascade = CascadeType.ALL) | ||
@JoinTable(joinColumns = @JoinColumn(name="customer_id"), inverseJoinColumns = @JoinColumn(name="product_id")) | ||
private List<Product> products; | ||
|
||
public int getId() { | ||
return id; | ||
} | ||
|
||
public void setId(int id) { | ||
this.id = id; | ||
} | ||
|
||
public List<Product> getProducts() { | ||
return products; | ||
} | ||
|
||
public void setProducts(List<Product> products) { | ||
this.products = products; | ||
} | ||
|
||
|
||
} |
40 changes: 40 additions & 0 deletions
40
mapping/association-mapping/ExampleApp/src/main/java/com/giriharan/ExampleApp/Library.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.giriharan.ExampleApp; | ||
|
||
import java.util.List; | ||
|
||
import javax.persistence.Entity; | ||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.GenerationType; | ||
import javax.persistence.Id; | ||
import javax.persistence.JoinColumn; | ||
import javax.persistence.JoinTable; | ||
import javax.persistence.OneToMany; | ||
|
||
@Entity | ||
public class Library { | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.AUTO) | ||
private int id; | ||
|
||
@OneToMany | ||
@JoinTable(name = "library_tb_book_tb", joinColumns = @JoinColumn(name = "library_id"),inverseJoinColumns = @JoinColumn(name = "book_id")) | ||
private List<Book> books; | ||
|
||
public int getId() { | ||
return id; | ||
} | ||
|
||
public void setId(int id) { | ||
this.id = id; | ||
} | ||
|
||
public List<Book> getBooks() { | ||
return books; | ||
} | ||
|
||
public void setBooks(List<Book> books) { | ||
this.books = books; | ||
} | ||
|
||
|
||
} |
Oops, something went wrong.