-
Notifications
You must be signed in to change notification settings - Fork 200
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c1b82c2
commit d7789b7
Showing
9 changed files
with
191 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
plugins { | ||
id "io.micronaut.build.internal.data-native-example" | ||
} | ||
|
||
application { | ||
mainClass = "example.Application" | ||
} | ||
|
||
micronaut { | ||
version libs.versions.micronaut.platform.get() | ||
runtime "netty" | ||
testRuntime "junit5" | ||
} | ||
|
||
dependencies { | ||
annotationProcessor projects.micronautDataProcessor | ||
annotationProcessor mnValidation.micronaut.validation | ||
annotationProcessor mnSql.hibernate.jpamodelgen | ||
compileOnly mnSerde.micronaut.serde.api | ||
implementation mn.micronaut.http.client | ||
implementation mnRxjava2.micronaut.rxjava2 | ||
implementation mnSql.micronaut.hibernate.jpa | ||
implementation projects.micronautDataHibernateJpa | ||
implementation mnValidation.validation | ||
|
||
runtimeOnly mnSql.micronaut.jdbc.tomcat | ||
runtimeOnly mnLogging.logback.classic | ||
runtimeOnly mnSql.h2 | ||
runtimeOnly mnValidation.micronaut.validation | ||
} | ||
|
||
tasks.withType(JavaCompile).configureEach { | ||
options.fork = true | ||
options.forkOptions.jvmArgs.add("-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:5005") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
skipDocumentation=true |
42 changes: 42 additions & 0 deletions
42
doc-examples/hibernate-bug-java/src/main/java/example/OperationLog.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package example; | ||
|
||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.GenerationType; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.IdClass; | ||
import org.hibernate.annotations.JdbcTypeCode; | ||
|
||
import java.sql.Types; | ||
import java.util.UUID; | ||
|
||
@Entity | ||
@IdClass(UUIDTenantId.class) | ||
public class OperationLog { | ||
|
||
int x = 9; | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.UUID) | ||
@JdbcTypeCode(Types.CHAR) | ||
private UUID id; | ||
|
||
@Id | ||
private String tenant; | ||
|
||
public UUID getId() { | ||
return id; | ||
} | ||
|
||
public void setId(UUID id) { | ||
this.id = id; | ||
} | ||
|
||
public String getTenant() { | ||
return tenant; | ||
} | ||
|
||
public void setTenant(String tenant) { | ||
this.tenant = tenant; | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
doc-examples/hibernate-bug-java/src/main/java/example/OperationLogRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package example; | ||
|
||
import io.micronaut.data.annotation.Repository; | ||
import io.micronaut.data.repository.GenericRepository; | ||
|
||
import java.util.Optional; | ||
import java.util.UUID; | ||
|
||
@Repository | ||
public interface OperationLogRepository extends GenericRepository<OperationLog, UUIDTenantId> { | ||
Optional<OperationLog> findOneByIdAndTenant(UUID id, String tenant); | ||
|
||
OperationLog save(OperationLog operationLog); | ||
} |
27 changes: 27 additions & 0 deletions
27
doc-examples/hibernate-bug-java/src/main/java/example/UUIDTenantId.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package example; | ||
|
||
import java.io.Serializable; | ||
import java.util.UUID; | ||
|
||
public class UUIDTenantId implements Serializable { | ||
|
||
private UUID id; | ||
|
||
private String tenant; | ||
|
||
public UUID getId() { | ||
return id; | ||
} | ||
|
||
public void setId(UUID id) { | ||
this.id = id; | ||
} | ||
|
||
public String getTenant() { | ||
return tenant; | ||
} | ||
|
||
public void setTenant(String tenant) { | ||
this.tenant = tenant; | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
doc-examples/hibernate-bug-java/src/main/resources/application.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
--- | ||
micronaut: | ||
application: | ||
name: data-example | ||
--- | ||
datasources: | ||
default: | ||
url: jdbc:h2:mem:devDb;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE;NON_KEYWORDS=USER | ||
driverClassName: org.h2.Driver | ||
username: sa | ||
password: '' | ||
jpa: | ||
default: | ||
properties: | ||
hibernate: | ||
hbm2ddl: | ||
auto: update | ||
compileTimeHibernateProxies: true |
18 changes: 18 additions & 0 deletions
18
doc-examples/hibernate-bug-java/src/main/resources/logback.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<configuration> | ||
|
||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> | ||
<encoder> | ||
<pattern>%cyan(%d{HH:mm:ss.SSS}) %gray([%thread]) %highlight(%-5level) %magenta(%logger{36}) - %msg%n</pattern> | ||
</encoder> | ||
</appender> | ||
|
||
<root level="info"> | ||
<appender-ref ref="STDOUT" /> | ||
</root> | ||
<!-- <logger name="example" level="trace" />--> | ||
<!-- <logger name="org.hibernate.SQL" level="trace" />--> | ||
<!-- <logger name="org.hibernate.type" level="trace" />--> | ||
<!-- <logger name="io.micronaut.http.client" level="trace" />--> | ||
<!-- <logger name="io.micronaut.context.condition" level="trace" />--> | ||
|
||
</configuration> |
34 changes: 34 additions & 0 deletions
34
doc-examples/hibernate-bug-java/src/test/java/example/MnHibUuidTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package example; | ||
|
||
import example.OperationLog; | ||
import example.OperationLogRepository; | ||
import io.micronaut.runtime.EmbeddedApplication; | ||
import io.micronaut.test.extensions.junit5.annotation.MicronautTest; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.Assertions; | ||
|
||
import jakarta.inject.Inject; | ||
|
||
import java.util.Optional; | ||
import java.util.UUID; | ||
|
||
@MicronautTest | ||
class MnHibUuidTest { | ||
|
||
@Inject | ||
EmbeddedApplication<?> application; | ||
|
||
@Inject | ||
OperationLogRepository repository; | ||
|
||
@Test | ||
void testItWorks() { | ||
OperationLog operationLog = new OperationLog(); | ||
operationLog.setId(UUID.randomUUID()); | ||
operationLog.setTenant("a1"); | ||
repository.save(operationLog); | ||
Optional<OperationLog> opt = repository.findOneByIdAndTenant(operationLog.getId(), operationLog.getTenant()); | ||
Assertions.assertTrue(opt.isPresent()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters