Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
2
20230403
Overview
Overview
Details
Activity
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
Patryk Czarnik
20230403
Commits
246795ed
Commit
246795ed
authored
Apr 25, 2023
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Dodanie drugiej bazy danych do projektu JPA
parent
6c44b96f
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
606 additions
and
1 deletions
+606
-1
pom.xml
PC29-HibenateNowy/pom.xml
+0
-1
Country.java
PC29-HibenateNowy/src/main/java/hr/model/Country.java
+57
-0
Department.java
PC29-HibenateNowy/src/main/java/hr/model/Department.java
+97
-0
Employee.java
PC29-HibenateNowy/src/main/java/hr/model/Employee.java
+152
-0
Job.java
PC29-HibenateNowy/src/main/java/hr/model/Job.java
+94
-0
Location.java
PC29-HibenateNowy/src/main/java/hr/model/Location.java
+91
-0
Region.java
PC29-HibenateNowy/src/main/java/hr/model/Region.java
+71
-0
OdczytajWszystkich2.java
...eNowy/src/main/java/hr/przyklady/OdczytajWszystkich2.java
+28
-0
persistence.xml
...-HibenateNowy/src/main/resources/META-INF/persistence.xml
+16
-0
No files found.
PC29-HibenateNowy/pom.xml
View file @
246795ed
...
@@ -28,7 +28,6 @@
...
@@ -28,7 +28,6 @@
</dependencies>
</dependencies>
<build>
<build>
<finalName>
Persistence9
</finalName>
<plugins>
<plugins>
<plugin>
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<groupId>
org.apache.maven.plugins
</groupId>
...
...
PC29-HibenateNowy/src/main/java/hr/model/Country.java
0 → 100644
View file @
246795ed
package
hr
.
model
;
import
java.io.Serializable
;
import
jakarta.persistence.*
;
/**
* The persistent class for the countries database table.
*
*/
@Entity
@Table
(
name
=
"countries"
)
@NamedQuery
(
name
=
"Country.findAll"
,
query
=
"SELECT c FROM Country c"
)
public
class
Country
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
@Id
@Column
(
name
=
"country_id"
)
private
String
countryId
;
@Column
(
name
=
"country_name"
)
private
String
countryName
;
//bi-directional many-to-one association to Region
@ManyToOne
@JoinColumn
(
name
=
"region_id"
)
private
Region
region
;
public
Country
()
{
}
public
String
getCountryId
()
{
return
this
.
countryId
;
}
public
void
setCountryId
(
String
countryId
)
{
this
.
countryId
=
countryId
;
}
public
String
getCountryName
()
{
return
this
.
countryName
;
}
public
void
setCountryName
(
String
countryName
)
{
this
.
countryName
=
countryName
;
}
public
Region
getRegion
()
{
return
this
.
region
;
}
public
void
setRegion
(
Region
region
)
{
this
.
region
=
region
;
}
}
\ No newline at end of file
PC29-HibenateNowy/src/main/java/hr/model/Department.java
0 → 100644
View file @
246795ed
package
hr
.
model
;
import
java.io.Serializable
;
import
jakarta.persistence.*
;
import
java.util.List
;
/**
* The persistent class for the departments database table.
*
*/
@Entity
@Table
(
name
=
"departments"
)
@NamedQuery
(
name
=
"Department.findAll"
,
query
=
"SELECT d FROM Department d"
)
public
class
Department
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
@Id
@SequenceGenerator
(
name
=
"DEPARTMENTS_DEPARTMENTID_GENERATOR"
,
sequenceName
=
"DEPARTMENTS_SEQ"
,
allocationSize
=
10
)
@GeneratedValue
(
strategy
=
GenerationType
.
SEQUENCE
,
generator
=
"DEPARTMENTS_DEPARTMENTID_GENERATOR"
)
@Column
(
name
=
"department_id"
)
private
Integer
departmentId
;
@Column
(
name
=
"department_name"
)
private
String
departmentName
;
@Column
(
name
=
"manager_id"
)
private
Integer
managerId
;
//uni-directional many-to-one association to Location
@ManyToOne
@JoinColumn
(
name
=
"location_id"
)
private
Location
location
;
//bi-directional many-to-one association to Employee
@OneToMany
(
mappedBy
=
"department"
)
private
List
<
Employee
>
employees
;
public
Department
()
{
}
public
Integer
getDepartmentId
()
{
return
this
.
departmentId
;
}
public
void
setDepartmentId
(
Integer
departmentId
)
{
this
.
departmentId
=
departmentId
;
}
public
String
getDepartmentName
()
{
return
this
.
departmentName
;
}
public
void
setDepartmentName
(
String
departmentName
)
{
this
.
departmentName
=
departmentName
;
}
public
Integer
getManagerId
()
{
return
this
.
managerId
;
}
public
void
setManagerId
(
Integer
managerId
)
{
this
.
managerId
=
managerId
;
}
public
Location
getLocation
()
{
return
this
.
location
;
}
public
void
setLocation
(
Location
location
)
{
this
.
location
=
location
;
}
public
List
<
Employee
>
getEmployees
()
{
return
this
.
employees
;
}
public
void
setEmployees
(
List
<
Employee
>
employees
)
{
this
.
employees
=
employees
;
}
public
Employee
addEmployee
(
Employee
employee
)
{
getEmployees
().
add
(
employee
);
employee
.
setDepartment
(
this
);
return
employee
;
}
public
Employee
removeEmployee
(
Employee
employee
)
{
getEmployees
().
remove
(
employee
);
employee
.
setDepartment
(
null
);
return
employee
;
}
}
\ No newline at end of file
PC29-HibenateNowy/src/main/java/hr/model/Employee.java
0 → 100644
View file @
246795ed
package
hr
.
model
;
import
java.io.Serializable
;
import
jakarta.persistence.*
;
import
java.math.BigDecimal
;
import
java.util.Date
;
/**
* The persistent class for the employees database table.
*
*/
@Entity
@Table
(
name
=
"employees"
)
@NamedQuery
(
name
=
"Employee.findAll"
,
query
=
"SELECT e FROM Employee e"
)
public
class
Employee
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
@Id
@SequenceGenerator
(
name
=
"EMPLOYEES_EMPLOYEEID_GENERATOR"
,
sequenceName
=
"EMPLOYEES_SEQ"
,
allocationSize
=
1
)
@GeneratedValue
(
strategy
=
GenerationType
.
SEQUENCE
,
generator
=
"EMPLOYEES_EMPLOYEEID_GENERATOR"
)
@Column
(
name
=
"employee_id"
)
private
Integer
employeeId
;
@Column
(
name
=
"commission_pct"
)
private
BigDecimal
commissionPct
;
private
String
email
;
@Column
(
name
=
"first_name"
)
private
String
firstName
;
@Temporal
(
TemporalType
.
DATE
)
@Column
(
name
=
"hire_date"
)
private
Date
hireDate
;
@Column
(
name
=
"last_name"
)
private
String
lastName
;
@Column
(
name
=
"phone_number"
)
private
String
phoneNumber
;
private
BigDecimal
salary
;
//bi-directional many-to-one association to Department
@ManyToOne
@JoinColumn
(
name
=
"department_id"
)
private
Department
department
;
//uni-directional many-to-one association to Employee
@ManyToOne
@JoinColumn
(
name
=
"manager_id"
)
private
Employee
manager
;
//bi-directional many-to-one association to Job
@ManyToOne
@JoinColumn
(
name
=
"job_id"
)
private
Job
job
;
public
Employee
()
{
}
public
Integer
getEmployeeId
()
{
return
this
.
employeeId
;
}
public
void
setEmployeeId
(
Integer
employeeId
)
{
this
.
employeeId
=
employeeId
;
}
public
BigDecimal
getCommissionPct
()
{
return
this
.
commissionPct
;
}
public
void
setCommissionPct
(
BigDecimal
commissionPct
)
{
this
.
commissionPct
=
commissionPct
;
}
public
String
getEmail
()
{
return
this
.
email
;
}
public
void
setEmail
(
String
email
)
{
this
.
email
=
email
;
}
public
String
getFirstName
()
{
return
this
.
firstName
;
}
public
void
setFirstName
(
String
firstName
)
{
this
.
firstName
=
firstName
;
}
public
Date
getHireDate
()
{
return
this
.
hireDate
;
}
public
void
setHireDate
(
Date
hireDate
)
{
this
.
hireDate
=
hireDate
;
}
public
String
getLastName
()
{
return
this
.
lastName
;
}
public
void
setLastName
(
String
lastName
)
{
this
.
lastName
=
lastName
;
}
public
String
getPhoneNumber
()
{
return
this
.
phoneNumber
;
}
public
void
setPhoneNumber
(
String
phoneNumber
)
{
this
.
phoneNumber
=
phoneNumber
;
}
public
BigDecimal
getSalary
()
{
return
this
.
salary
;
}
public
void
setSalary
(
BigDecimal
salary
)
{
this
.
salary
=
salary
;
}
public
Department
getDepartment
()
{
return
this
.
department
;
}
public
void
setDepartment
(
Department
department
)
{
this
.
department
=
department
;
}
public
Employee
getManager
()
{
return
this
.
manager
;
}
public
void
setManager
(
Employee
manager
)
{
this
.
manager
=
manager
;
}
public
Job
getJob
()
{
return
this
.
job
;
}
public
void
setJob
(
Job
job
)
{
this
.
job
=
job
;
}
}
\ No newline at end of file
PC29-HibenateNowy/src/main/java/hr/model/Job.java
0 → 100644
View file @
246795ed
package
hr
.
model
;
import
java.io.Serializable
;
import
jakarta.persistence.*
;
import
java.math.BigDecimal
;
import
java.util.List
;
/**
* The persistent class for the jobs database table.
*
*/
@Entity
@Table
(
name
=
"jobs"
)
@NamedQuery
(
name
=
"Job.findAll"
,
query
=
"SELECT j FROM Job j"
)
public
class
Job
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
@Id
@Column
(
name
=
"job_id"
)
private
String
jobId
;
@Column
(
name
=
"job_title"
)
private
String
jobTitle
;
@Column
(
name
=
"max_salary"
)
private
BigDecimal
maxSalary
;
@Column
(
name
=
"min_salary"
)
private
BigDecimal
minSalary
;
//bi-directional many-to-one association to Employee
@OneToMany
(
mappedBy
=
"job"
)
private
List
<
Employee
>
employees
;
public
Job
()
{
}
public
String
getJobId
()
{
return
this
.
jobId
;
}
public
void
setJobId
(
String
jobId
)
{
this
.
jobId
=
jobId
;
}
public
String
getJobTitle
()
{
return
this
.
jobTitle
;
}
public
void
setJobTitle
(
String
jobTitle
)
{
this
.
jobTitle
=
jobTitle
;
}
public
BigDecimal
getMaxSalary
()
{
return
this
.
maxSalary
;
}
public
void
setMaxSalary
(
BigDecimal
maxSalary
)
{
this
.
maxSalary
=
maxSalary
;
}
public
BigDecimal
getMinSalary
()
{
return
this
.
minSalary
;
}
public
void
setMinSalary
(
BigDecimal
minSalary
)
{
this
.
minSalary
=
minSalary
;
}
public
List
<
Employee
>
getEmployees
()
{
return
this
.
employees
;
}
public
void
setEmployees
(
List
<
Employee
>
employees
)
{
this
.
employees
=
employees
;
}
public
Employee
addEmployee
(
Employee
employee
)
{
getEmployees
().
add
(
employee
);
employee
.
setJob
(
this
);
return
employee
;
}
public
Employee
removeEmployee
(
Employee
employee
)
{
getEmployees
().
remove
(
employee
);
employee
.
setJob
(
null
);
return
employee
;
}
}
\ No newline at end of file
PC29-HibenateNowy/src/main/java/hr/model/Location.java
0 → 100644
View file @
246795ed
package
hr
.
model
;
import
java.io.Serializable
;
import
jakarta.persistence.*
;
/**
* The persistent class for the locations database table.
*
*/
@Entity
@Table
(
name
=
"locations"
)
@NamedQuery
(
name
=
"Location.findAll"
,
query
=
"SELECT l FROM Location l"
)
public
class
Location
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
@Id
@SequenceGenerator
(
name
=
"LOCATIONS_LOCATIONID_GENERATOR"
,
sequenceName
=
"LOCATIONS_SEQ"
,
allocationSize
=
100
)
@GeneratedValue
(
strategy
=
GenerationType
.
SEQUENCE
,
generator
=
"LOCATIONS_LOCATIONID_GENERATOR"
)
@Column
(
name
=
"location_id"
)
private
Integer
locationId
;
private
String
city
;
@Column
(
name
=
"postal_code"
)
private
String
postalCode
;
@Column
(
name
=
"state_province"
)
private
String
stateProvince
;
@Column
(
name
=
"street_address"
)
private
String
streetAddress
;
//uni-directional many-to-one association to Country
@ManyToOne
@JoinColumn
(
name
=
"country_id"
)
private
Country
country
;
public
Location
()
{
}
public
Integer
getLocationId
()
{
return
this
.
locationId
;
}
public
void
setLocationId
(
Integer
locationId
)
{
this
.
locationId
=
locationId
;
}
public
String
getCity
()
{
return
this
.
city
;
}
public
void
setCity
(
String
city
)
{
this
.
city
=
city
;
}
public
String
getPostalCode
()
{
return
this
.
postalCode
;
}
public
void
setPostalCode
(
String
postalCode
)
{
this
.
postalCode
=
postalCode
;
}
public
String
getStateProvince
()
{
return
this
.
stateProvince
;
}
public
void
setStateProvince
(
String
stateProvince
)
{
this
.
stateProvince
=
stateProvince
;
}
public
String
getStreetAddress
()
{
return
this
.
streetAddress
;
}
public
void
setStreetAddress
(
String
streetAddress
)
{
this
.
streetAddress
=
streetAddress
;
}
public
Country
getCountry
()
{
return
this
.
country
;
}
public
void
setCountry
(
Country
country
)
{
this
.
country
=
country
;
}
}
\ No newline at end of file
PC29-HibenateNowy/src/main/java/hr/model/Region.java
0 → 100644
View file @
246795ed
package
hr
.
model
;
import
java.io.Serializable
;
import
jakarta.persistence.*
;
import
java.util.List
;
/**
* The persistent class for the regions database table.
*
*/
@Entity
@Table
(
name
=
"regions"
)
@NamedQuery
(
name
=
"Region.findAll"
,
query
=
"SELECT r FROM Region r"
)
public
class
Region
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
@Id
@Column
(
name
=
"region_id"
)
private
Integer
regionId
;
@Column
(
name
=
"region_name"
)
private
String
regionName
;
//bi-directional many-to-one association to Country
@OneToMany
(
mappedBy
=
"region"
)
private
List
<
Country
>
countries
;
public
Region
()
{
}
public
Integer
getRegionId
()
{
return
this
.
regionId
;
}
public
void
setRegionId
(
Integer
regionId
)
{
this
.
regionId
=
regionId
;
}
public
String
getRegionName
()
{
return
this
.
regionName
;
}
public
void
setRegionName
(
String
regionName
)
{
this
.
regionName
=
regionName
;
}
public
List
<
Country
>
getCountries
()
{
return
this
.
countries
;
}
public
void
setCountries
(
List
<
Country
>
countries
)
{
this
.
countries
=
countries
;
}
public
Country
addCountry
(
Country
country
)
{
getCountries
().
add
(
country
);
country
.
setRegion
(
this
);
return
country
;
}
public
Country
removeCountry
(
Country
country
)
{
getCountries
().
remove
(
country
);
country
.
setRegion
(
null
);
return
country
;
}
}
\ No newline at end of file
PC29-HibenateNowy/src/main/java/hr/przyklady/OdczytajWszystkich2.java
0 → 100644
View file @
246795ed
package
hr
.
przyklady
;
import
java.util.List
;
import
hr.model.Employee
;
import
jakarta.persistence.EntityManager
;
import
jakarta.persistence.EntityManagerFactory
;
import
jakarta.persistence.Persistence
;
import
jakarta.persistence.TypedQuery
;
public
class
OdczytajWszystkich2
{
public
static
void
main
(
String
[]
args
)
{
EntityManagerFactory
emf
=
Persistence
.
createEntityManagerFactory
(
"hr"
);
EntityManager
em
=
emf
.
createEntityManager
();
TypedQuery
<
Employee
>
query
=
em
.
createNamedQuery
(
"Employee.findAll"
,
Employee
.
class
);
List
<
Employee
>
lista
=
query
.
getResultList
();
for
(
Employee
emp
:
lista
)
{
System
.
out
.
println
(
emp
.
getFirstName
()
+
" "
+
emp
.
getLastName
()
+
" "
+
emp
.
getSalary
());
}
em
.
close
();
emf
.
close
();
}
}
PC29-HibenateNowy/src/main/resources/META-INF/persistence.xml
View file @
246795ed
...
@@ -14,4 +14,20 @@
...
@@ -14,4 +14,20 @@
<property
name=
"hibernate.show_sql"
value=
"true"
/>
<property
name=
"hibernate.show_sql"
value=
"true"
/>
</properties>
</properties>
</persistence-unit>
</persistence-unit>
<persistence-unit
name=
"hr"
transaction-type=
"RESOURCE_LOCAL"
>
<class>
hr.model.Country
</class>
<class>
hr.model.Department
</class>
<class>
hr.model.Employee
</class>
<class>
hr.model.Job
</class>
<class>
hr.model.Location
</class>
<class>
hr.model.Region
</class>
<properties>
<property
name=
"javax.persistence.jdbc.url"
value=
"jdbc:postgresql://localhost:5432/hr"
/>
<property
name=
"javax.persistence.jdbc.user"
value=
"kurs"
/>
<property
name=
"javax.persistence.jdbc.password"
value=
"abc123"
/>
<property
name=
"javax.persistence.jdbc.driver"
value=
"org.postgresql.Driver"
/>
<property
name=
"hibernate.show_sql"
value=
"true"
/>
</properties>
</persistence-unit>
</persistence>
</persistence>
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