-
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
Nareshit
authored and
Nareshit
committed
Apr 29, 2021
1 parent
b1b430a
commit 938c4eb
Showing
29 changed files
with
660 additions
and
7 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
HBProj77-OneToOneFK/target/classes/META-INF/maven/nit/HBProj75-ManyToManyBi/pom.properties
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
4 changes: 2 additions & 2 deletions
4
HBProj78-OneToOnePK/target/classes/META-INF/maven/nit/HBProj75-ManyToManyBi/pom.properties
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
4 changes: 2 additions & 2 deletions
4
...anyBi-CollectionId/target/classes/META-INF/maven/nit/HBProj75-ManyToManyBi/pom.properties
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
4 changes: 2 additions & 2 deletions
4
...j87Anno-OneToOneFK/target/classes/META-INF/maven/nit/HBProj75-ManyToManyBi/pom.properties
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
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,27 @@ | ||
<?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 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 kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-14"> | ||
<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,23 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>HBProj88Anno-OneToOnePK</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
HBProj88Anno-OneToOnePK/.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 |
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=14 | ||
org.eclipse.jdt.core.compiler.compliance=14 | ||
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=14 |
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,102 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<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>nit</groupId> | ||
<artifactId>HBProj75-ManyToManyBi</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
|
||
<name>HBProj75-ManyToManyBi</name> | ||
<!-- FIXME change it to the project's website --> | ||
<url>http://www.example.com</url> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<maven.compiler.source>14</maven.compiler.source> | ||
<maven.compiler.target>14</maven.compiler.target> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>4.11</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-core --> | ||
<dependency> | ||
<groupId>org.hibernate</groupId> | ||
<artifactId>hibernate-core</artifactId> | ||
<version>5.4.30.Final</version> | ||
</dependency> | ||
<!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-hikaricp --> | ||
<dependency> | ||
<groupId>org.hibernate</groupId> | ||
<artifactId>hibernate-hikaricp</artifactId> | ||
<version>5.4.30.Final</version> | ||
</dependency> | ||
<!-- https://mvnrepository.com/artifact/com.oracle.ojdbc/ojdbc8 --> | ||
<dependency> | ||
<groupId>com.oracle.ojdbc</groupId> | ||
<artifactId>ojdbc8</artifactId> | ||
<version>19.3.0.0</version> | ||
</dependency> | ||
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok --> | ||
<dependency> | ||
<groupId>org.projectlombok</groupId> | ||
<artifactId>lombok</artifactId> | ||
<version>1.18.20</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
|
||
|
||
</dependencies> | ||
|
||
<build> | ||
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) --> | ||
<plugins> | ||
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle --> | ||
<plugin> | ||
<artifactId>maven-clean-plugin</artifactId> | ||
<version>3.1.0</version> | ||
</plugin> | ||
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging --> | ||
<plugin> | ||
<artifactId>maven-resources-plugin</artifactId> | ||
<version>3.0.2</version> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>3.8.0</version> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<version>2.22.1</version> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-jar-plugin</artifactId> | ||
<version>3.0.2</version> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-install-plugin</artifactId> | ||
<version>2.5.2</version> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-deploy-plugin</artifactId> | ||
<version>2.8.2</version> | ||
</plugin> | ||
<!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle --> | ||
<plugin> | ||
<artifactId>maven-site-plugin</artifactId> | ||
<version>3.7.1</version> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-project-info-reports-plugin</artifactId> | ||
<version>3.0.0</version> | ||
</plugin> | ||
</plugins> | ||
</pluginManagement> | ||
</build> | ||
</project> |
38 changes: 38 additions & 0 deletions
38
HBProj88Anno-OneToOnePK/src/main/java/com/nt/cfgs/hibernate.cfg.xml
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,38 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE hibernate-configuration PUBLIC | ||
"-//Hibernate/Hibernate Configuration DTD 3.0//EN" | ||
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"> | ||
<hibernate-configuration> | ||
<session-factory> | ||
<!-- Connection properties (mandatory except driver class name) --> | ||
<property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property> | ||
<property name="connection.url">jdbc:oracle:thin:@localhost:1521:xe</property> | ||
<property name="connection.username">system</property> | ||
<property name="connection.password">manager</property> | ||
|
||
<!-- <property name="connection.driver_class">com.mysql.cj.jdbc.Driver</property> | ||
<property name="connection.url">jdbc:mysql:///nthb915db</property> | ||
<property name="connection.username">root</property> | ||
<property name="connection.password">root</property> | ||
--> | ||
|
||
<!-- Connection provider to work with Proxool --> | ||
<property name="connection.provider_class">org.hibernate.hikaricp.internal.HikariCPConnectionProvider</property> | ||
|
||
<!-- HikariCP settings --> | ||
<property name="hikari.connectionTimeout">50000</property> | ||
<property name="hibernate.hikari.minimumIdle">10</property> | ||
<property name="hibernate.hikari.maximumPoolSize">20</property> | ||
<property name="hibernate.hikari.idleTimeout">30000</property> | ||
|
||
|
||
<!-- Hibernate properties (optional) --> | ||
<property name="show_sql">true</property> | ||
<property name="format_sql">true</property> | ||
<property name="hbm2ddl.auto">update</property> | ||
<property name="dialect">org.hibernate.dialect.Oracle10gDialect</property> | ||
<!-- mapping classes --> | ||
<mapping class="com.nt.entity.Student"/> | ||
<mapping class="com.nt.entity.LibraryMembership"/> | ||
</session-factory> | ||
</hibernate-configuration> |
9 changes: 9 additions & 0 deletions
9
HBProj88Anno-OneToOnePK/src/main/java/com/nt/dao/OneToOnePKDAO.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,9 @@ | ||
package com.nt.dao; | ||
|
||
public interface OneToOnePKDAO { | ||
public void saveDataUsingParent(); | ||
public void loadDataUsingChild(); | ||
public void removeDataUsingChild(); | ||
|
||
|
||
} |
83 changes: 83 additions & 0 deletions
83
HBProj88Anno-OneToOnePK/src/main/java/com/nt/dao/OneToOnePKDAOImpl.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,83 @@ | ||
package com.nt.dao; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
|
||
import javax.persistence.Query; | ||
|
||
import org.hibernate.HibernateException; | ||
import org.hibernate.Session; | ||
import org.hibernate.Transaction; | ||
|
||
import com.nt.entity.LibraryMembership; | ||
import com.nt.entity.Student; | ||
import com.nt.utility.HibernateUtil; | ||
|
||
public class OneToOnePKDAOImpl implements OneToOnePKDAO { | ||
|
||
@Override | ||
public void saveDataUsingParent() { | ||
Transaction tx=null; | ||
try(Session ses=HibernateUtil.getSession()){ | ||
//prepare objs | ||
Student s1=new Student("raja", "hyd",LocalDateTime.of(1990,10, 21, 5,50)); | ||
Student s2=new Student("rajesh", "hyd",LocalDateTime.of(1991,11, 12, 5,50)); | ||
LibraryMembership library1=new LibraryMembership("gold", "Miss.Karnua",LocalDateTime.now(), LocalDateTime.of(2041,4,21,9,22)); | ||
LibraryMembership library2=new LibraryMembership("silver", "Miss.Karnua",LocalDateTime.now(), LocalDateTime.of(2031,1,21,9,22)); | ||
s1.setLibraryDetails(library1); library1.setStudentDetails(s1); | ||
s2.setLibraryDetails(library2); library2.setStudentDetails(s2); | ||
tx=ses.beginTransaction(); | ||
ses.save(s1); ses.save(s2); | ||
tx.commit(); | ||
System.out.println("Objects are saved"); | ||
} | ||
catch(HibernateException he) { | ||
he.printStackTrace(); | ||
if(tx!=null || tx.getStatus()!=null || tx.getRollbackOnly() ) { | ||
tx.rollback(); | ||
System.out.println("objects are not saved"); | ||
} | ||
} | ||
|
||
} | ||
|
||
@Override | ||
public void loadDataUsingChild() { | ||
Transaction tx=null; | ||
try(Session ses=HibernateUtil.getSession()){ | ||
//prepare and execute query | ||
Query query=ses.createQuery("from LibraryMembership"); | ||
List<LibraryMembership> list=query.getResultList(); | ||
list.forEach(lib->{ | ||
System.out.println("child ::"+lib); | ||
Student st=lib.getStudentDetails(); | ||
System.out.println("parent ::"+st); | ||
}); | ||
}//try | ||
catch(HibernateException he) { | ||
he.printStackTrace(); | ||
} | ||
}//method | ||
|
||
@Override | ||
public void removeDataUsingChild() { | ||
Transaction tx=null; | ||
try(Session ses=HibernateUtil.getSession()){ | ||
//Load child object | ||
LibraryMembership lib=ses.get(LibraryMembership.class,1); | ||
tx=ses.beginTransaction(); | ||
ses.delete(lib); | ||
tx.commit(); | ||
System.out.println("child and its associated parent obj is deleted"); | ||
} | ||
catch(HibernateException he) { | ||
he.printStackTrace(); | ||
if(tx!=null || tx.getStatus()!=null || tx.getRollbackOnly() ) { | ||
tx.rollback(); | ||
System.out.println("objects are not deleted"); | ||
} | ||
} | ||
|
||
} | ||
|
||
}//class |
Oops, something went wrong.