FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
java-code-example/HibernateInsertNull/src/CheckNull.java at master · cherkavi/java-code-example · GitHub
cherkavi
/
java-code-example
Public
Notifications
You must be signed in to change notification settings
Fork
4
Star
0
Code
Issues
0
Pull requests
42
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
java-code-example
/
HibernateInsertNull
/
src
/
CheckNull.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
executable file
·
83 lines (67 loc) · 2.81 KB
Breadcrumbs
java-code-example
/
HibernateInsertNull
/
src
/
CheckNull.java
Copy path
File metadata and controls
executable file
·
83 lines (67 loc) · 2.81 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import
java
.
util
.
Date
;
import
org
.
hibernate
.
Session
;
import
org
.
hibernate
.
cfg
.
AnnotationConfiguration
;
import
org
.
hibernate
.
cfg
.
Configuration
;
import
org
.
hibernate
.
criterion
.
Restrictions
;
import
tables
.
Temp
;
public
class
CheckNull
{
public
static
void
main
(
String
[]
args
){
Configuration
cfg
=
new
AnnotationConfiguration
()
.
addAnnotatedClass
(
Temp
.
class
)
.
setProperty
(
"hibernate.dialect"
,
"org.hibernate.dialect.OracleDialect"
)
.
setProperty
(
"hibernate.connection.driver_class"
,
"oracle.jdbc.driver.OracleDriver"
)
.
setProperty
(
"hibernate.connection.url"
,
"jdbc:oracle:thin:@127.0.0.1:1521:XE"
)
.
setProperty
(
"hibernate.connection.username"
,
"technik"
)
.
setProperty
(
"hibernate.connection.password"
,
"technik"
)
;
Session
session
=
cfg
.
buildSessionFactory
().
openSession
();
// readAndSaveValue(session);
createAndSaveValue
(
session
);
}
private
static
void
createAndSaveValue
(
Session
session
){
Temp
value
=
new
Temp
();
// value.setId(10);
value
.
setName
(
"created name"
);
value
.
setTimeStamp
(
new
Date
());
System
.
out
.
println
(
"Readed object:"
+
value
);
session
.
beginTransaction
();
session
.
save
(
value
);
value
.
setTimeStamp
(
new
Date
());
session
.
getTransaction
().
commit
();
System
.
out
.
println
(
"Saved (1) object:"
+
value
);
session
.
beginTransaction
();
value
.
setTimeStamp
(
null
);
session
.
update
(
value
);
session
.
getTransaction
().
commit
();
System
.
out
.
println
(
"Saved (2) object:"
+
value
);
value
=(
Temp
)
session
.
createCriteria
(
Temp
.
class
).
add
(
Restrictions
.
eq
(
"id"
,
value
.
getId
())).
uniqueResult
();
System
.
out
.
println
(
"Readed object:"
+
value
);
/*
*
Readed object:Temp [id=null, name=created name, timeStamp=Wed Sep 28 22:22:04 EEST 2011]
Saved (1) object:Temp [id=200, name=created name, timeStamp=Wed Sep 28 22:22:04 EEST 2011]
Saved (2) object:Temp [id=200, name=created name, timeStamp=null]
Readed object:Temp [id=200, name=created name, timeStamp=null] */
}
private
static
void
readAndSaveValue
(
Session
session
){
Temp
value
=(
Temp
)
session
.
createCriteria
(
Temp
.
class
).
add
(
Restrictions
.
eq
(
"id"
,
4
)).
uniqueResult
();
System
.
out
.
println
(
"Readed object:"
+
value
);
session
.
beginTransaction
();
value
.
setTimeStamp
(
new
Date
());
session
.
getTransaction
().
commit
();
System
.
out
.
println
(
"Saved (1) object:"
+
value
);
session
.
beginTransaction
();
value
.
setTimeStamp
(
null
);
session
.
merge
(
value
);
session
.
getTransaction
().
commit
();
System
.
out
.
println
(
"Saved (2) object:"
+
value
);
value
=(
Temp
)
session
.
createCriteria
(
Temp
.
class
).
add
(
Restrictions
.
eq
(
"id"
,
4
)).
uniqueResult
();
System
.
out
.
println
(
"Readed object:"
+
value
);
/*
*
Readed object:Temp [id=4, name=4:value, timeStamp=null]
Saved (1) object:Temp [id=4, name=4:value, timeStamp=Wed Sep 28 22:13:36 EEST 2011]
Saved (2) object:Temp [id=4, name=4:value, timeStamp=null]
Readed object:Temp [id=4, name=4:value, timeStamp=null] */
}
}
Back
|
FazBrowse Home
|
New Git URL