An open API service indexing awesome lists of open source software.

https://github.com/thitikorn-nupan/spring-boot-jpa-hibernate-crud-h2-one-to-many-and-mockito-and-logback-configuration


https://github.com/thitikorn-nupan/spring-boot-jpa-hibernate-crud-h2-one-to-many-and-mockito-and-logback-configuration

h2-database jpa-hibernate junit logback logging-library mockito one-to-many resttemplate spring-boot

Last synced: about 1 month ago
JSON representation

Awesome Lists containing this project

README

          

# Spring boot crud h2 (one to many)


- Testing with mockito
- Using logback for debug
- Using Jpa/hibernate

Developed by [ttknpde-v](https://github.com/ttknpde-v)

# What things I got this project
- [x] How to set up logback pattern on xml file


```xml











%white(%d{ISO8601}) %highlight(%-5level) [%yellow(%t)] : %msg%n%throwable






${LOG_PATH}/${LOG_FILE_NAME}.log

%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level : %msg%n





${LOG_PATH}/archived/${LOG_FILE_NAME}-%d{yyyy-MM-dd}.%i.log


10MB

















```

`example inside this project`

```java
package com.ttknpdev.springbootonetomanyh2.log;
import com.ttknpdev.springbootonetomanyh2.command.CommandClient;
import com.ttknpdev.springbootonetomanyh2.dao.many.AddressDao;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public interface Logging {
Logger addressDao = LoggerFactory.getLogger(AddressDao.class);
Logger commandClient = LoggerFactory.getLogger(CommandClient.class);
}
```

- [x] Understand more to use anotations @OneToMany and @ManyToOne


`this example's inside entity Employee`

```java
@OneToMany(cascade = CascadeType.ALL)
@JoinColumn(name = "eid")
private List

addresses;
/*
{
"eid":"E001",
"fullname":"Peter Parker",
"age":23,
"salary":25000.0,
"addresses":[ // json array
{
"aid":"A001",
"city":"Bangkok",
"country":"Thailand",
"details":"123 soi.1/3 ABC Village"
},
{
"aid":"A002",
"city":"Bangkok",
"country":"Thailand",
"details":"122 soi.1/3 ABC Village"
}
]
}
*/
```

`this example's inside entity Address`

```java
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "eid")
@JsonIgnore
private Employee employee;
```

- [x] Repeat , How to use RestTemplate (within the Spring framework) for sending any http method I wanted [example](https://github.com/ttknpde-v/spring-boot-jpa-hibernate-crud-h2-one-to-many-and-mockito-and-logback-configuration/blob/main/src/main/java/com/ttknpdev/springbootonetomanyh2/command/CommandClient.java)
- `import org.springframework.web.client.RestTemplate;`
- `import org.springframework.http.*;`


- [x] Testing this application with mokito [example](https://github.com/ttknpde-v/spring-boot-jpa-hibernate-crud-h2-one-to-many-and-mockito-and-logback-configuration/blob/main/src/test/java/com/ttknpdev/springbootonetomanyh2/MyBusinessLogic.java)


`these are dependency for using mockito`

```xml

org.junit.jupiter
junit-jupiter-api
5.8.1
test


org.junit.jupiter
junit-jupiter-engine
5.8.1
test

```

# My Description

How difference to the last project about one to many ,

I know better to use logging library. (Default config and setting log back config) And this project

I understand How to use JPA for relations one to many better. (using @OneToMany for List Entity,@manytoone for Entity)

I know it's bad performance. And again I use mock for testing my logic.