Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
assignments_new
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Suresh Kumar
assignments_new
Commits
47a3a560
Commit
47a3a560
authored
Jun 28, 2022
by
Suresh Kumar
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Hibernate
parent
6c965654
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
289 additions
and
0 deletions
+289
-0
pom.xml
RelationShipBetweenStudentsAndCourses/pom.xml
+40
-0
App.java
...rc/main/java/com/hibernatemanytomanyrelationship/App.java
+64
-0
Courses.java
...ain/java/com/hibernatemanytomanyrelationship/Courses.java
+61
-0
Students.java
...in/java/com/hibernatemanytomanyrelationship/Students.java
+68
-0
hibernate.cfg.xml
...BetweenStudentsAndCourses/src/main/java/hibernate.cfg.xml
+18
-0
AppTest.java
...est/java/com/hibernatemanytomanyrelationship/AppTest.java
+38
-0
No files found.
RelationShipBetweenStudentsAndCourses/pom.xml
0 → 100644
View file @
47a3a560
<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.hibernatemanytomanyrelationship
</groupId>
<artifactId>
RelationShipBetweenStudentsAndCourses
</artifactId>
<version>
0.0.1-SNAPSHOT
</version>
<packaging>
jar
</packaging>
<name>
RelationShipBetweenStudentsAndCourses
</name>
<url>
http://maven.apache.org
</url>
<properties>
<project.build.sourceEncoding>
UTF-8
</project.build.sourceEncoding>
</properties>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-core -->
<dependency>
<groupId>
org.hibernate
</groupId>
<artifactId>
hibernate-core
</artifactId>
<version>
5.4.5.Final
</version>
</dependency>
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
<dependency>
<groupId>
mysql
</groupId>
<artifactId>
mysql-connector-java
</artifactId>
<version>
8.0.15
</version>
</dependency>
<dependency>
<groupId>
junit
</groupId>
<artifactId>
junit
</artifactId>
<version>
3.8.1
</version>
<scope>
test
</scope>
</dependency>
</dependencies>
</project>
\ No newline at end of file
RelationShipBetweenStudentsAndCourses/src/main/java/com/hibernatemanytomanyrelationship/App.java
0 → 100644
View file @
47a3a560
package
com
.
hibernatemanytomanyrelationship
;
import
java.util.*
;
import
org.hibernate.Session
;
import
org.hibernate.SessionFactory
;
import
org.hibernate.Transaction
;
import
org.hibernate.cfg.Configuration
;
public
class
App
{
public
static
void
main
(
String
[]
args
)
{
System
.
out
.
println
(
"Project Started....!"
);
Configuration
cfg
=
new
Configuration
();
cfg
.
configure
(
"hibernate.cfg.xml"
);
SessionFactory
factory
=
cfg
.
buildSessionFactory
();
Students
s1
=
new
Students
();
Students
s2
=
new
Students
();
s1
.
setSid
(
5
);
s1
.
setRno
(
"102"
);
s1
.
setName
(
"M_Asad Iqbal"
);
s2
.
setSid
(
6
);
s2
.
setRno
(
"106"
);
s2
.
setName
(
"Arsam Ali"
);
Courses
c1
=
new
Courses
();
Courses
c2
=
new
Courses
();
c1
.
setCid
(
5
);
c1
.
setCoursename
(
"Java"
);
c2
.
setCid
(
6
);
c2
.
setCoursename
(
"JavaScript"
);
List
<
Students
>
list1
=
new
ArrayList
<
Students
>();
List
<
Courses
>
list2
=
new
ArrayList
<
Courses
>();
list1
.
add
(
s1
);
list1
.
add
(
s2
);
list2
.
add
(
c1
);
list2
.
add
(
c2
);
s1
.
setCourses
(
list2
);
c2
.
setStudents
(
list1
);
Session
s
=
factory
.
openSession
();
Transaction
txt
=
s
.
beginTransaction
();
s
.
save
(
s1
);
s
.
save
(
s2
);
s
.
save
(
c1
);
s
.
save
(
c2
);
txt
.
commit
();
s
.
close
();
}
}
RelationShipBetweenStudentsAndCourses/src/main/java/com/hibernatemanytomanyrelationship/Courses.java
0 → 100644
View file @
47a3a560
package
com
.
hibernatemanytomanyrelationship
;
import
java.util.List
;
import
javax.persistence.Column
;
import
javax.persistence.Entity
;
import
javax.persistence.Id
;
import
javax.persistence.ManyToMany
;
@Entity
public
class
Courses
{
@Id
private
int
cid
;
@Column
(
name
=
"course_name"
)
private
String
coursename
;
@ManyToMany
(
mappedBy
=
"courses"
)
private
List
<
Students
>
students
;
public
int
getCid
()
{
return
cid
;
}
public
void
setCid
(
int
cid
)
{
this
.
cid
=
cid
;
}
public
String
getCoursename
()
{
return
coursename
;
}
public
void
setCoursename
(
String
coursename
)
{
this
.
coursename
=
coursename
;
}
public
List
<
Students
>
getStudents
()
{
return
students
;
}
public
void
setStudents
(
List
<
Students
>
students
)
{
this
.
students
=
students
;
}
public
Courses
(
int
cid
,
String
coursename
,
List
<
Students
>
students
)
{
super
();
this
.
cid
=
cid
;
this
.
coursename
=
coursename
;
this
.
students
=
students
;
}
public
Courses
()
{
super
();
// TODO Auto-generated constructor stub
}
}
RelationShipBetweenStudentsAndCourses/src/main/java/com/hibernatemanytomanyrelationship/Students.java
0 → 100644
View file @
47a3a560
package
com
.
hibernatemanytomanyrelationship
;
import
java.util.List
;
import
javax.persistence.Entity
;
import
javax.persistence.Id
;
import
javax.persistence.ManyToMany
;
@Entity
public
class
Students
{
@Id
private
int
sid
;
private
String
rno
;
private
String
name
;
@ManyToMany
private
List
<
Courses
>
courses
;
public
int
getSid
()
{
return
sid
;
}
public
void
setSid
(
int
sid
)
{
this
.
sid
=
sid
;
}
public
String
getRno
()
{
return
rno
;
}
public
void
setRno
(
String
rno
)
{
this
.
rno
=
rno
;
}
public
String
getName
()
{
return
name
;
}
public
void
setName
(
String
name
)
{
this
.
name
=
name
;
}
public
List
<
Courses
>
getCourses
()
{
return
courses
;
}
public
void
setCourses
(
List
<
Courses
>
courses
)
{
this
.
courses
=
courses
;
}
public
Students
(
int
sid
,
String
rno
,
String
name
,
List
<
Courses
>
courses
)
{
super
();
this
.
sid
=
sid
;
this
.
rno
=
rno
;
this
.
name
=
name
;
this
.
courses
=
courses
;
}
public
Students
()
{
super
();
// TODO Auto-generated constructor stub
}
}
\ No newline at end of file
RelationShipBetweenStudentsAndCourses/src/main/java/hibernate.cfg.xml
0 → 100644
View file @
47a3a560
<?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>
<property
name=
"connection.driver_class"
>
com.mysql.cj.jdbc.Driver
</property>
<property
name=
"connection.url"
>
jdbc:mysql://localhost:3306/myhibernate
</property>
<property
name=
"connection.username"
>
root
</property>
<property
name=
"connection.password"
>
nisum123
</property>
<property
name=
"dialect"
>
org.hibernate.dialect.MySQL55Dialect
</property>
<property
name=
"hbm2ddl.auto"
>
update
</property>
<property
name=
"show_sql"
>
true
</property>
<mapping
class=
"com.hibernatemanytomanyrelationship.Students"
/>
<mapping
class=
"com.hibernatemanytomanyrelationship.Courses"
/>
</session-factory>
</hibernate-configuration>
\ No newline at end of file
RelationShipBetweenStudentsAndCourses/src/test/java/com/hibernatemanytomanyrelationship/AppTest.java
0 → 100644
View file @
47a3a560
package
com
.
hibernatemanytomanyrelationship
;
import
junit.framework.Test
;
import
junit.framework.TestCase
;
import
junit.framework.TestSuite
;
/**
* Unit test for simple App.
*/
public
class
AppTest
extends
TestCase
{
/**
* Create the test case
*
* @param testName name of the test case
*/
public
AppTest
(
String
testName
)
{
super
(
testName
);
}
/**
* @return the suite of tests being tested
*/
public
static
Test
suite
()
{
return
new
TestSuite
(
AppTest
.
class
);
}
/**
* Rigourous Test :-)
*/
public
void
testApp
()
{
assertTrue
(
true
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment