micronaut-projects / micronaut-projects/micronaut-data
Schema generator failing to create schema for Oracle db when mapped entity is configured to use schema
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 482
- Forks
- 229
- Avg merge
- 1d 7h
- Merged PRs (30d)
- 32
Description
### Expected Behavior
Having entity like this
```
@MappedEntity(schema = "library", value = "book")
public record Book(
@Id
@GeneratedValue
Long id,
String title) {
}
```
and configuration
```
datasources.default.db-type=oracle
datasources.default.dialect=ORACLE
micronaut.application.name=mn-data-schema
datasources.default.schema-generate=CREATE_DROP
datasources.default.driver-class-name=oracle.jdbc.OracleDriver
```
Micronaut should be able to save and read from the repository
```
@JdbcRepository(dialect = Dialect.ORACLE)
public interface BookRepository extends CrudRepository {
}
```
for this mapping.
### Actual Behaviour
`bookRepository.save(book)` fails with the error
```
io.micronaut.data.exceptions.DataAccessException: Error executing PERSIST: ORA-04043: Object "LIBRARY"."BOOK" does not exist.
https://docs.oracle.com/error-help/db/ora-04043/
```
Because schema generator fails to create schema. When adding this property to the config
```
datasources.default.schema-generate-name=LIBRARY
```
then the failure is reported in SchemaGenerator
```
Message: Failed to create the schema: ORA-01501: CREATE DATABASE failed
ORA-01100: database already mounted
https://docs.oracle.com/error-help/db/ora-01501/
Path Taken:
new @i.m.c.a.Context i.m.d.j.c.SchemaGenerator(List configurations, JdbcSchemaHandler schemaHandler, Environment environment)
at io.micronaut.context.DefaultBeanContext.resolveByBeanFactory(DefaultBeanContext.java:2350)
at io.micronaut.context.DefaultBeanContext.createRegistration(DefaultBeanContext.java:3146)
at io.micronaut.context.SingletonScope.getOrCreate(SingletonScope.java:80)
at io.micronaut.context.DefaultBeanContext.intializeEagerBean(DefaultBeanContext.java:3035)
at io.micronaut.context.DefaultBeanContext.initializeEagerBean(DefaultBeanContext.java:2704)
at io.micronaut.context.DefaultBeanContext.initializeContext(DefaultBeanContext.java:2032)
... 8 more
Caused by: io.micronaut.data.exceptions.DataAccessException: Failed to create the schema: ORA-01501: CREATE DATABASE failed
ORA-01100: database already mounted
https://docs.oracle.com/error-help/db/ora-01501/
at io.micronaut.data.jdbc.operations.DefaultJdbcSchemaHandler.createSchema(DefaultJdbcSchemaHandler.java:47)
at io.micronaut.data.jdbc.config.SchemaGenerator.createSchema(SchemaGenerator.java:129)
```
and app fails to start.
### Steps To Reproduce
Extract attached application and run tests.
[mn-data-schema.zip](https://github.com/user-attachments/files/19682830/mn-data-schema.zip)
### Environment Information
Any
### Example Application
_No response_
### Version
4.8.0 (and earlier)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the tests from the attached application to reproduce the Oracle failure. Read SchemaGenerator.java and DefaultJdbcSchemaHandler.java at the reported stack-trace locations, then verify that schema generation supports the mapped library schema without attempting database creation, and that BookRepository can save and read Book records.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, sql
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100