marioosh.net

mini blog / notes

The conversion of a varchar data type to a datetime data type resulted in an out-of-range value (Konwersja typu danych varchar na typ danych datetime spowodowała utworzenie wartości leżącej poza zakresem)

This error can be result of wrong `dateformat` setting on database. Example below. ERROR – `dmy` dateformat: SET DATEFORMAT dmy; DECLARE @datetime datetime = ‘2021-12-31’; SELECT CASE WHEN @datetime >= ‘2021-11-22’ THEN 1 ELSE 0 END;SET DATEFORMAT dmy; DECLARE @datetime datetime = ‘2021-12-31’; SELECT case when @datetime >= ‘2021-11-22’ then 1 else 0 end; OK Read more about The conversion of a varchar data type to a datetime data type resulted in an out-of-range value (Konwersja typu danych varchar na typ danych datetime spowodowała utworzenie wartości leżącej poza zakresem)[…]

Native query with Enum as parameter

public interface ItemRepository extends JpaRepository<Item, Long> { @Query(value = "select * from items where type = :#{#type?.name()}", nativeQuery = true) List<Item> findByType(@Param("type") ItemType type); }   public enum ItemType { NORMAL, LARGE };public interface ItemRepository extends JpaRepository<Item, Long> { @Query(value = "select * from items where type = :#{#type?.name()}", nativeQuery = true) List<Item> findByType(@Param("type") ItemType Read more about Native query with Enum as parameter[…]

Chain ‘DOCKER’ does not exist

Error when docker make networking… iptables failed: iptables –wait -t nat -A DOCKER … Chain ‘DOCKER’ does not existiptables failed: iptables –wait -t nat -A DOCKER … Chain ‘DOCKER’ does not exist Solution $ systemctl restart docker$ systemctl restart docker

Optional @Value

// default: 60 @Value("${test-value:60}") private int minutes;   // default: null @Value("${test-value2:#{null}}") private String text;// default: 60 @Value("${test-value:60}") private int minutes; // default: null @Value("${test-value2:#{null}}") private String text;

SpEL in @Query (Spring Data)

@Query("select t from Test t where name = :#{#data.name} and type = :#{#data.type}") List<User> findByData(@Param("data") Data data);   public class Data { private String name; private DataType type; }@Query("select t from Test t where name = :#{#data.name} and type = :#{#data.type}") List<User> findByData(@Param("data") Data data); public class Data { private String name; private DataType type; Read more about SpEL in @Query (Spring Data)[…]

@ViewChild

@ViewChild can access only local template of component, not parent or child components. @Component({ selector: ‘app-login’, template: ` <re-captcha></re-captcha> <div #refname></div> `, styleUrls: [’./login.component.css’] }) export class LoginComponent implements OnInit, AfterViewInit {   @ViewChild(RecaptchaComponent) reCaptcha: RecaptchaComponent; @ViewChild(’refname’) input: ElementRef;   constructor() { console.log(this.reCaptcha); // null }   ngAfterViewInit(): void { console.log(this.reCaptcha); // not null } Read more about @ViewChild[…]

Map<String,String> in JPA Entity

@Entity @Table(name="product") public class Product extends AbstractEntity {   @Id @GeneratedValue(strategy=GenerationType.AUTO) private Long id;   @ElementCollection(fetch = FetchType.EAGER) @JoinTable(name="product_attribute", joinColumns=@JoinColumn(name="product_id")) @MapKeyColumn(name="key") @Column(name="value") private Map<String, String> attributes = new HashMap<String, String>();   // …   }@Entity @Table(name="product") public class Product extends AbstractEntity { @Id @GeneratedValue(strategy=GenerationType.AUTO) private Long id; @ElementCollection(fetch = FetchType.EAGER) @JoinTable(name="product_attribute", joinColumns=@JoinColumn(name="product_id")) @MapKeyColumn(name="key") @Column(name="value") private Read more about Map<String,String> in JPA Entity[…]

Spring Data JPA: LIKE with OR query

@RepositoryRestResource public interface ProductRepository extends JpaRepository<Product, String> { List<Product> findByTitleContainingIgnoreCaseOrIdContainingIgnoreCase( @Param("q") String name, @Param("q") String id); }@RepositoryRestResource public interface ProductRepository extends JpaRepository<Product, String> { List<Product> findByTitleContainingIgnoreCaseOrIdContainingIgnoreCase( @Param("q") String name, @Param("q") String id); } Request path: GET https://localhost:8443/api/products/search/findByTitleContainingIgnoreCaseOrIdContainingIgnoreCase?q=…GET https://localhost:8443/api/products/search/findByTitleContainingIgnoreCaseOrIdContainingIgnoreCase?q=… If we need shorter request path: // GET https://localhost:8443/api/products/search/custom?q=… @RestResource(path = "custom") List<Product> findByTitleContainingIgnoreCaseOrIdContainingIgnoreCase( @Param("q") String name, Read more about Spring Data JPA: LIKE with OR query[…]