ZonedDateTime field created and implemented
This commit is contained in:
parent
05b449a115
commit
237977fb5c
@ -3,6 +3,8 @@ import jakarta.persistence.*;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
|
||||
import java.time.ZonedDateTime;
|
||||
|
||||
@Entity
|
||||
@Table(name="films_info")
|
||||
public class FilmInfoModel {
|
||||
@ -30,6 +32,10 @@ public class FilmInfoModel {
|
||||
@Column(name="category_id")
|
||||
private int filmCategory;
|
||||
|
||||
@Column(name="last_update", columnDefinition = "TIMESTAMP WITH TIME ZONE")
|
||||
private ZonedDateTime lastUpdate;
|
||||
|
||||
|
||||
public FilmInfoModel() {}
|
||||
|
||||
public int getId() {
|
||||
@ -88,6 +94,14 @@ public class FilmInfoModel {
|
||||
this.filmCategory = filmCategory;
|
||||
}
|
||||
|
||||
public ZonedDateTime getLastUpdate() {
|
||||
return lastUpdate;
|
||||
}
|
||||
|
||||
public void setLastUpdate(ZonedDateTime lastUpdate) {
|
||||
this.lastUpdate = lastUpdate;
|
||||
}
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "language_id", referencedColumnName = "language_id", insertable=false, updatable = false)
|
||||
private FilmLanguageModel filmLanguageModel;
|
||||
@ -116,13 +130,13 @@ public class FilmInfoModel {
|
||||
this.filmModel = filmModel;
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public String toString() {
|
||||
// return "FilmInfo{" +
|
||||
// "id=" + id +
|
||||
// ", filmDescription=" + filmDescription + '\n' +
|
||||
// ", releaseYear=" + releaseYear + ", filmLanguage=" + filmLanguage + '\n' +
|
||||
// ", filmLength=" + filmLength + ", filmRating=" + filmRating + '\n' +
|
||||
// ", filmCategory=" + filmCategory + '}';
|
||||
// }
|
||||
@Override
|
||||
public String toString() {
|
||||
return "FilmInfo{" +
|
||||
"id=" + id +
|
||||
", filmDescription=" + filmDescription + '\n' +
|
||||
", releaseYear=" + releaseYear + ", filmLanguage=" + filmLanguage + '\n' +
|
||||
", filmLength=" + filmLength + ", filmRating=" + filmRating + '\n' +
|
||||
", filmCategory=" + filmCategory + '\n' + ", lastUpdate=" + lastUpdate + '}';
|
||||
}
|
||||
}
|
||||
|
@ -24,7 +24,6 @@ public class Main {
|
||||
// queries.getFilmByLangYear("Japanese", "2006");
|
||||
// queries.getFilmByLangCategory("Action", "Japanese");
|
||||
// queries.getAllFilmsByPage(4, session);
|
||||
// queries.addFilm("TestMovieTitle", session);
|
||||
|
||||
Transaction tx = null;
|
||||
try {
|
||||
|
@ -3,6 +3,8 @@ package org.example;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.hibernate.query.Query;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -90,37 +92,10 @@ public class Queries {
|
||||
return query.getResultList();
|
||||
}
|
||||
|
||||
public void addFilm(String filmTitle, Session session) {
|
||||
|
||||
Transaction transaction = null;
|
||||
|
||||
try {
|
||||
transaction = session.beginTransaction();
|
||||
FilmModel filmModel = new FilmModel();
|
||||
filmModel.setFilmTitle(filmTitle);
|
||||
|
||||
FilmInfoModel filmInfo = new FilmInfoModel();
|
||||
filmInfo.setFilmDescription("testowy opis filmu");
|
||||
|
||||
filmModel.setFilmInfo(filmInfo);
|
||||
filmInfo.setFilmModel(filmModel);
|
||||
|
||||
session.save(filmModel);
|
||||
|
||||
transaction.commit();
|
||||
|
||||
} catch (Exception e) {
|
||||
if (transaction != null) {
|
||||
transaction.rollback();
|
||||
}
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static FilmModel createFilmModel() {
|
||||
FilmModel filmModel = new FilmModel();
|
||||
FilmInfoModel filmInfoModel = new FilmInfoModel();
|
||||
// filmModel.setId(1001);
|
||||
|
||||
filmModel.setFilmTitle("Test Film Title");
|
||||
filmInfoModel.setFilmDescription("Test Movie Description");
|
||||
filmInfoModel.setReleaseYear(2023);
|
||||
@ -129,6 +104,9 @@ public class Queries {
|
||||
filmInfoModel.setFilmRating("test");
|
||||
filmInfoModel.setFilmCategory(1);
|
||||
|
||||
ZonedDateTime currentTimestamp = ZonedDateTime.now();
|
||||
filmInfoModel.setLastUpdate(currentTimestamp);
|
||||
|
||||
filmModel.setFilmInfo(filmInfoModel);
|
||||
|
||||
return filmModel;
|
||||
|
@ -1,21 +1,23 @@
|
||||
<hibernate-configuration>
|
||||
<session-factory>
|
||||
<!-- ustawienia połączenia z bazą danych -->
|
||||
<!-- ustawienia polaczenia z baza danych -->
|
||||
<property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
|
||||
<property name="hibernate.connection.url">jdbc:postgresql://localhost:5432/PRA2024</property>
|
||||
<property name="hibernate.connection.username">postgres</property>
|
||||
<property name="hibernate.connection.password">password</property>
|
||||
|
||||
<!-- ustawienie domyslnej strefy czasowej -->
|
||||
<property name="hibernate.jdbc.time_zone">Europe/Warsaw</property>
|
||||
|
||||
<!-- inne ustawienia Hibernate -->
|
||||
<property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
|
||||
<property name="hibernate.show_sql">true</property>
|
||||
<property name="hibernate.hbm2ddl.auto">update</property>
|
||||
|
||||
<!-- skanowanie pakietów z encjami -->
|
||||
<!-- skanowanie pakietow z encjami -->
|
||||
<mapping class="org.example.FilmModel"/>
|
||||
<mapping class="org.example.FilmInfoModel"/>
|
||||
<mapping class="org.example.FilmLanguageModel"/>
|
||||
<mapping class="org.example.FilmCategoryModel"/>
|
||||
|
||||
</session-factory>
|
||||
</hibernate-configuration>
|
||||
|
Loading…
Reference in New Issue
Block a user