Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
javab_20230928
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
javab_20230928
Commits
586018e4
Commit
586018e4
authored
Oct 20, 2023
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
nie wiem co zmieniłem
parent
2d4f23a4
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
3 deletions
+13
-3
Zapis_Update.java
...src/main/java/sklep/przyklady_hibernate/Zapis_Update.java
+13
-3
No files found.
PC27-SklepHibernate/src/main/java/sklep/przyklady_hibernate/Zapis_Update.java
View file @
586018e4
...
...
@@ -11,9 +11,9 @@ public class Zapis_Update {
public
static
void
main
(
String
[]
args
)
{
try
(
EntityManagerFactory
emf
=
Persistence
.
createEntityManagerFactory
(
"sklep"
);
EntityManager
em
=
emf
.
createEntityManager
())
{
Scanner
sc
=
new
Scanner
(
System
.
in
);
EntityManager
em
=
emf
.
createEntityManager
())
{
Scanner
sc
=
new
Scanner
(
System
.
in
);
System
.
out
.
println
(
"Rozpoczynam transakcję"
);
EntityTransaction
transakcja
=
em
.
getTransaction
();
transakcja
.
begin
();
...
...
@@ -50,6 +50,17 @@ public class Zapis_Update {
if
(!
opis
.
isEmpty
())
{
product
.
setDescription
(
opis
);
}
// Operacja flush wymusza wykonanie poleceń DML (INSERT, UPDATE, DELETE) na bazie, ale nie zatwierdza transakcji
// Nie ma obowiązku wykonywać flush. Gdy na końcu zrobimy commit, to Hibernate i tak zflushuje dane...
System
.
out
.
println
(
"Czy zrobić teraz flush? [T/N] "
);
String
taknie
=
sc
.
nextLine
().
trim
().
toUpperCase
();
switch
(
taknie
)
{
case
"T"
,
"Y"
->
{
em
.
flush
();
System
.
out
.
println
(
"Zrobione"
);
}
}
}
// Do tej pory zmiany zostały dokonane w obiektach znajdujących się w pamięci.
...
...
@@ -69,7 +80,6 @@ public class Zapis_Update {
}
// w pozostałych przypadkach nie ma ani commit, ani rollback → zmiany nie zostaną zapisane
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
...
...
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