Conversation
| @Type(type = "jsonb") | ||
| @Column(name = "aux_data", columnDefinition = "text") | ||
| public String getAuxData() |
There was a problem hiding this comment.
Máš to ako string. Na string nepotrebuješ jsonb. Ten využiješ keby si mal JsonNode, alebo List, a iné.
Naviac tam máš aj columDefinition z JPA a aj hibernatí @Type. :)
There was a problem hiding this comment.
Jo a miesto toho možeš použiť DB agnostic @Clob od JPA. Ten by mal fungovať dobre s TEXT type v Postgresql.
There was a problem hiding this comment.
Ako String to je iba kvoli tomu, ze API malo s JsonNode problemy (v DB je to skutocne jsonb). Preto tam musi byt aj @Type. Zatial som to teda urobil, ze entita ma JsonNode, API ma String a prevadza sa to v ramci fromApi()/toApi().
There was a problem hiding this comment.
Ok, tak aspoň odstrániť ten columnDefinition = "text".
There was a problem hiding this comment.
Ten tam zase musi byt kvoli testom, pretoze HSQLDB nema jsonb.
| @Type(type = "jsonb") | ||
| @Column(columnDefinition = "text") | ||
| public String getData() |
There was a problem hiding this comment.
Rovnaký problém ako u auxData.
| this.name = name; | ||
| } | ||
|
|
||
| @Type(type = "pgsql_enum") |
There was a problem hiding this comment.
Bude stačiť @Enumerated(EnumType.STRING) a @Column od JPA na definovanie typu.
Ten @Type(type = "pgsql_enum") je hibernatí duplicita.
There was a problem hiding this comment.
Bolo to potrebne ked som vytvaral enum aj v postgrese. Ale pre konzistenciu som to zmenil a odstranil.
002cb71 to
4e81e85
Compare
| public static Builder builder() | ||
| { | ||
| return new Builder(); | ||
| } | ||
|
|
||
| public String getTagName() | ||
| { | ||
| return tagName; | ||
| } | ||
|
|
||
| public TagType getTagType() | ||
| { | ||
| return tagType; | ||
| } | ||
|
|
||
| public Boolean isEnabled() | ||
| { | ||
| return enabled; | ||
| } | ||
|
|
||
| public static class Builder | ||
| { | ||
|
|
||
| private String tagName; | ||
| private TagType tagType; | ||
| private boolean enabled; | ||
|
|
||
| private Builder() | ||
| { | ||
| } | ||
|
|
||
| public Builder tagName(String tagName) | ||
| { | ||
| this.tagName = tagName; | ||
| return this; | ||
| } | ||
|
|
||
| public Builder tagType(TagType tagType) | ||
| { | ||
| this.tagType = tagType; | ||
| return this; | ||
| } | ||
|
|
||
| public Builder enabled(boolean enabled) | ||
| { | ||
| this.enabled = enabled; | ||
| return this; | ||
| } | ||
|
|
||
| public AuxDataFilter build() | ||
| { | ||
| return new AuxDataFilter(tagName, tagType, enabled); | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
Toto sa dá celkom dobre skomprimovať. https://projectlombok.org/features/Builder
There was a problem hiding this comment.
O tom viem, akurat v momentalnej verzii shonga lombok nie je...
Aj tak som ho ale pridaval pri implementacii REST API, cize ho asi mozem pridat aj tu.
|
Pls nepoužívaj git push -f :) Aspoň nie kým nie je pull request resolved. |
| @Setter | ||
| @Entity | ||
| @Immutable | ||
| @Table(name = "arr_aux_data") |
There was a problem hiding this comment.
Tu vytváraš tabuľku v DB s názvom arr_aux_data, ale zároveň v init.sql vytváraš view s rovnakým názvom. Ten view je zdá sa mi už len zabudnutý pozostatok na zmazanie?
There was a problem hiding this comment.
arr_aux_data ma skutocne byt view (ktory jednoducho mapuje aux_data na jednotlive fieldy, aby som to nemusel robit v jave). V init.sql ho definujem a entita je potom vytvorena na pracu s nim.
There was a problem hiding this comment.
Nejak nikde nevidím kde sa ten view používa. A mal by sa volať nejak inak ako tá entita.
Snažím sa rozbehnúť projekt lokálne a dostávam potom error pri inicializácii že entita už existuje:
Exception in thread "main" javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not execute statement at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:154) at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:181) at org.hibernate.query.internal.AbstractProducedQuery.executeUpdate(AbstractProducedQuery.java:1614) at cz.cesnet.shongo.controller.util.NativeQuery.executeNativeUpdate(NativeQuery.java:275) at cz.cesnet.shongo.controller.Controller.initializeDatabase(Controller.java:945) at cz.cesnet.shongo.controller.Controller.main(Controller.java:1081) Caused by: org.hibernate.exception.SQLGrammarException: could not execute statement at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:103) at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:42) at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:113) at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:99) at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:200) at org.hibernate.engine.query.spi.NativeSQLQueryPlan.performExecuteUpdate(NativeSQLQueryPlan.java:107) at org.hibernate.internal.SessionImpl.executeNativeUpdate(SessionImpl.java:1491) at org.hibernate.query.internal.NativeQueryImpl.doExecuteUpdate(NativeQueryImpl.java:295) at org.hibernate.query.internal.AbstractProducedQuery.executeUpdate(AbstractProducedQuery.java:1605) ... 3 more Caused by: org.postgresql.util.PSQLException: ERROR: "arr_aux_data" is not a view
There was a problem hiding this comment.
Pouziva sa v ReservationRequestManager ako nahrada AuxDataService, ktora sa ti predtym nepozdavala:
private List<AuxDataMerged> getAuxData(AbstractReservationRequest reservationRequest, AuxDataFilter filter)
{
String queryString = "SELECT arr.tagName, rt.tag.type, arr.enabled, arr.data, rt.tag.data" +
" FROM AbstractReservationRequestAuxData arr" +
" JOIN ResourceSpecification res_spec ON res_spec.id = arr.specification.id" +
" JOIN ResourceTag rt ON rt.resource.id = res_spec.resource.id" +
" WHERE rt.tag.name = arr.tagName" +
" AND arr.id = :id";
....
}Ten error vyskakuje preto, ze najprv sa vytvori table kvoli JPA az potom sa zavola init.sql kde sa vytvara ten view.
Pridaval som to kvoli tomu aj do migration, ale zabudol som to pushnut, moja chyba.
| @Setter | ||
| @Entity | ||
| @Immutable |
There was a problem hiding this comment.
@immutable (ktorý je mimochodom od Hibernate) a @Setter nad jedným POJO nedáva zmysel.
Najvačší zmysel mi dáva pridávať k všetkým @entity
@DaTa (namiesto @Getter a @Setter)
@NoArgsConstructor (potrebný pre Hibernate)
There was a problem hiding this comment.
@Immutable sa pouziva, pretoze je to entita k viewu. Je ale pravda, ze @Setter nedava zmysel.
No description provided.