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
- Host: GitHub
- URL: https://github.com/thitikorn-nupan/spring-boot-jpa-hibernate-crud-h2-one-to-many-and-mockito-and-logback-configuration
- Owner: Thitikorn-Nupan
- Created: 2023-10-25T09:55:06.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2023-11-01T14:37:16.000Z (almost 2 years ago)
- Last Synced: 2025-05-12T12:00:55.114Z (5 months ago)
- Topics: h2-database, jpa-hibernate, junit, logback, logging-library, mockito, one-to-many, resttemplate, spring-boot
- Language: Java
- Homepage:
- Size: 14.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Spring boot crud h2 (one to many)
- Testing with mockito
- Using logback for debug
- Using Jpa/hibernateDeveloped 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
addresses;
`this example's inside entity Employee`
```java
@OneToMany(cascade = CascadeType.ALL)
@JoinColumn(name = "eid")
private List
/*
{
"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.