Skip to content

Instantly share code, notes, and snippets.

View FrancescoJo's full-sized avatar
🤒
Out sick

Hwan Jo FrancescoJo

🤒
Out sick
View GitHub Profile
@FrancescoJo
FrancescoJo / JPA_ERRORS.kt
Last active November 16, 2023 02:35
Hibernate error while upgrading Spring boot 2.7 to 3.0(Hibernate 5.x to 6.1)
// UserEntity.kt
@Entity
@Table(name = "users")
class UserEntity(
@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
val id: Long = 0L,
@Column(name = "isDeleted")
var isDeleted: Boolean = false,
@FrancescoJo
FrancescoJo / SpringDIQualifierUsage.kt
Last active March 31, 2023 08:54
How can we avoid DI error in this scenario without any annotations such as @primary, @qualifier, @resource?
@Repository(UserReadonlyRepository.NAME)
interface UserReadonlyRepository {
suspend fun findById(userId: UUID): User?
companion object {
const val NAME = "a.b.c.UserReadonlyRepository"
}
}
@Repository(UserRepository.NAME)
@FrancescoJo
FrancescoJo / codegen.kt
Last active August 2, 2022 02:04
Are there a spring RestController based codegen like this?
// given:
interface SomeController {
@RequestMapping(GET, "/someApi")
fun someApi(): Response1
}
@RestController
class SomeControllerImpl : SomeController {
override fun someApi1(): Response1 {
// ...
@FrancescoJo
FrancescoJo / CustomBeanConfig.kt
Created May 26, 2022 12:31
Spring Framework Custom annotation as Bean loader
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory
import org.springframework.beans.factory.support.BeanDefinitionRegistry
import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor
import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider
import org.springframework.context.annotation.Configuration
import org.springframework.core.type.filter.AnnotationTypeFilter
@Configuration
class AnnotationConfig : BeanDefinitionRegistryPostProcessor {
override fun postProcessBeanFactory(beanFactory: ConfigurableListableBeanFactory) {
@FrancescoJo
FrancescoJo / example.jsh
Created January 18, 2022 05:41
Run jshell as script engine
//usr/bin/env jshell --show-version "$0" "$@"; exit $?
public class Runner {
public static void main(final String[] args) {
System.out.println("Runner#main");
}
}
System.out.println("Executing class");
Runner.main(new String[0]);
@FrancescoJo
FrancescoJo / fancy-console.js
Created August 2, 2019 14:25
Facebook "STOP!" code for Google chrome
console.log("%cGood to go!", "font: 2em roboto; color: yellow; background-color: green;");
@FrancescoJo
FrancescoJo / AnimalClassfication.java
Last active June 27, 2019 01:01
An example to demonstrate animal classification system in Java 1.8.x.
class Animal { }
class Reptile extends Animal { }
class Bird extends Animal { }
interface MobileLife {
// Every classes derived from this interface should implement common features on it.
void move(double displacement);
double getDistance();
@FrancescoJo
FrancescoJo / AnimalClassfication.dart
Created June 17, 2019 13:38
An example to demonstrate animal classification system in Dart 2.x.
class Animal { }
class Reptile extends Animal { }
class Bird extends Animal { }
mixin MobileLife {
// We don't need to implement _move on every classes using this mixin, since mixin can include state.
var _distance = 0.0;
void _move(double displacement) {
@FrancescoJo
FrancescoJo / spring-jpa-disable-automatic-method-derivation.kt
Last active June 5, 2019 09:13
How to disable spring-jpa automatic method derivation
interface UserRepository : JpaRepository<User, Long>, UserRepositoryExtension
interface UserRepositoryExtension {
/*
* Here we get exception as following:
*
* Caused by: java.lang.IllegalArgumentException: Failed to create query for method
* public abstract User UserRepositoryExtension.getByRoleCriteria(java.lang.String,java.util.Set)!
* At least 2 parameter(s) provided but only 1 parameter(s) present in query.
*
interface EnumWithKey<T, K> {
val T.key: K
}
/*
* The reified type parameter lets you call the function without explicitly
* passing the Class-object.
*/
inline fun <reified T : Enum<T>, R> EnumWithKey<T, R>.byKey(key: R): T? {
return enumValues<T>().find { it.key == key }