Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@MongoEntity with database parameter does not detect database when using mongo panache #23813

Closed
romilpunetha opened this issue Feb 19, 2022 · 5 comments · Fixed by #23973
Closed
Labels
Milestone

Comments

@romilpunetha
Copy link

romilpunetha commented Feb 19, 2022

Describe the bug

The following is my code structure:

public interface BaseMongoRepository<T extends BaseMongoEntity>
         extends ReactivePanacheMongoRepository<T>  {}

public interface UserRepository 
        extends BaseMongoRepository<UserEntity> {}

public class BaseMongoRepositoryImpl<T extends BaseMongoEntity> 
        implements BaseMongoRepository<T> {}

public class UserRepositoryImpl
        extends BaseMongoRepositoryImpl<UserEntity>
        implements UserRepository

@MongoEntity(database = "userDB", collection= "users")
public class User {}

When I'm running this code, mongo panache fails with IllegalArgumentException:

The database attribute was not set for the @MongoEntity annotation and neither was the database property configured for the default Mongo Client (via 'quarkus.mongodb.database').

If I pass the default client using quarkus.mongodb.database, all my collections are created in the same database. However, the collections args for @MongoEntity works fine.

Expected behavior

When passing @MongoEntity(database = "userDB"), the collection should be created in the userDB database.

Actual behavior

If no default database is passed in application.properties, an error is thrown. Else the collection is created in the default database.

How to Reproduce?

No response

Output of uname -a or ver

Darwin Kernel Version 21.1.0: Wed Oct 13 17:33:01 PDT 2021; root:xnu-8019.41.5~1/RELEASE_ARM64_T6000 arm64

Output of java -version

openjdk version "17.0.2" 2022-01-18 OpenJDK Runtime Environment Homebrew (build 17.0.2+0) OpenJDK 64-Bit Server VM Homebrew (build 17.0.2+0, mixed mode, sharing)

GraalVM version (if different from Java)

No response

Quarkus version or git rev

2.7.0

Build tool (ie. output of mvnw --version or gradlew --version)

Java version: 17.0.2, vendor: Homebrew, runtime: /opt/homebrew/Cellar/openjdk/17.0.2/libexec/openjdk.jdk/Contents/Home Default locale: en_IN, platform encoding: UTF-8 OS name: "mac os x", version: "12.0.1", arch: "aarch64", family: "mac"

Additional information

No response

@romilpunetha romilpunetha added the kind/bug Something isn't working label Feb 19, 2022
@quarkus-bot
Copy link

quarkus-bot bot commented Feb 19, 2022

/cc @FroMage, @evanchooly, @loicmathieu

@loicmathieu
Copy link
Contributor

@romilpunetha can you link to a reproducer or upload one inside the issue ? This would help us on it a lot.

@romilpunetha
Copy link
Author

romilpunetha commented Feb 21, 2022

@loicmathieu

Here it is:
https://github.com/romilpunetha/quarkus-mongo-panache-demo/tree/main/mongodb-panache-quickstart

The following is the annotation on my UserEntity class:
@MongoEntity(database = "userDB", collection = "users")

However, the db is created using the base db config:
quarkus.mongodb.database=Users

Screenshot 2022-02-21 at 4 45 43 PM

@romilpunetha
Copy link
Author

@loicmathieu Did you get a chance to look into this?
We're about to move our workloads to production and it'd be difficult moving the collections into their respective DBs later.

@loicmathieu
Copy link
Contributor

Hi @romilpunetha there is indead a bug inside the reactive implementation that didn't take the database name from the entity.
I provided a PR to fix it.

@loicmathieu loicmathieu added this to the 2.8 - main milestone Feb 25, 2022
@gsmet gsmet modified the milestones: 2.8 - main, 2.7.3.Final Mar 1, 2022
gsmet pushed a commit to gsmet/quarkus that referenced this issue Mar 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants