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

Support multiple tables under one entity #32

Open
lavrukov opened this issue Feb 28, 2024 · 7 comments
Open

Support multiple tables under one entity #32

lavrukov opened this issue Feb 28, 2024 · 7 comments
Assignees
Labels
feature New feature or request

Comments

@lavrukov
Copy link
Contributor

We need a possibility to work with couple tables under one Entity.

The most convenient way for us - create table with something like tableName by Tx.Current.get().getRepositoryTransaction().table(entityCls, tableName)

In this case we have to think at least about:

  • names in projections
  • behavior in SchemaChecker
@nvamelichev
Copy link
Collaborator

Did you try dynamic entities (@Schema.Dynamic), they call the entity's NamingStrategy.getNameForClass() each time the table is used. I think Audit Trails in YC has used this feature once (you can ask them and search in git history; currently they don't use it.)

@lavrukov
Copy link
Contributor Author

Did you try dynamic entities (@Schema.Dynamic), they call the entity's NamingStrategy.getNameForClass() each time the table is used. I think Audit Trails in YC has used this feature once (you can ask them and search in git history; currently they don't use it.)

Dynamic hard to use. I propose something like this #33

@lavrukov lavrukov self-assigned this Mar 6, 2024
@lavrukov lavrukov added the feature New feature or request label Mar 6, 2024
@lavrukov lavrukov changed the title Support multiply talbes under one entity. Support multiply talbes under one entity Mar 6, 2024
@lavrukov lavrukov changed the title Support multiply talbes under one entity Support multiple tables under one entity Apr 1, 2024
@estekhin
Copy link

estekhin commented Apr 1, 2024

Instead of plain table name, it would be better to pass the whole NamingStrategy to support renames for columns too.

@nvamelichev
Copy link
Collaborator

Supporting custom NamingStrategy would be more complex, we'll have to have same-entity table with essentially different Schemas (because column names would be different for different invocations of BaseDb.table(...)). Just supplying a custom table name would be much simpler, I think.

In addition, the NamingStrategy's setName(JavaField) method is just a bad bad influence. We plan to make JavaField.name immutable (eventually) but adding new NamingStrategy use cases and possibly new implementations - does not help that goal.

@estekhin
Copy link

estekhin commented Apr 2, 2024

We are using custom NamingStrategy for some entities which we do not control (can't change their annotations or fields), and right now we are registering that NamingStrategy via static SchemaRegistry.getDefault().namingOverrides().add(type, strategy).

The problem with that method is that it must be called before any other code that will query EntitySchema for that type, otherwise the schema registry will initialize the default naming strategy for that type.

Passing the NamingStrategy at the point where the table is being created feels like the cleanest way to remove or at least minimize the dependencies on the static state.

I don't get the point about "bad bad setName(JavaField)". There should be a way to override column names, and it could provide a better api than setName(JavaField).
setName(JavaField) is just the implementation detail, but we still need a feature to rename columns for entities which code is outside of our control.

g-sg-v pushed a commit to g-sg-v/yoj-project that referenced this issue Dec 23, 2024
g-sg-v pushed a commit to g-sg-v/yoj-project that referenced this issue Dec 23, 2024
g-sg-v pushed a commit to g-sg-v/yoj-project that referenced this issue Dec 23, 2024
g-sg-v pushed a commit to g-sg-v/yoj-project that referenced this issue Dec 23, 2024
g-sg-v pushed a commit to g-sg-v/yoj-project that referenced this issue Dec 27, 2024
g-sg-v pushed a commit to g-sg-v/yoj-project that referenced this issue Dec 27, 2024
g-sg-v pushed a commit to g-sg-v/yoj-project that referenced this issue Dec 27, 2024
g-sg-v pushed a commit to g-sg-v/yoj-project that referenced this issue Dec 27, 2024
g-sg-v pushed a commit to g-sg-v/yoj-project that referenced this issue Dec 27, 2024
g-sg-v pushed a commit to g-sg-v/yoj-project that referenced this issue Dec 27, 2024
g-sg-v pushed a commit to g-sg-v/yoj-project that referenced this issue Dec 27, 2024
g-sg-v pushed a commit to g-sg-v/yoj-project that referenced this issue Dec 27, 2024
g-sg-v pushed a commit to g-sg-v/yoj-project that referenced this issue Dec 27, 2024
g-sg-v pushed a commit to g-sg-v/yoj-project that referenced this issue Dec 27, 2024
g-sg-v pushed a commit to g-sg-v/yoj-project that referenced this issue Dec 27, 2024
@nvamelichev
Copy link
Collaborator

nvamelichev commented Dec 27, 2024

🎉 We've introduced basic table name changing functionality in v2.6.5!
It is currently an @ExperimentalApi (i.e., can change or disappear at any moment) but the functionality is reasonably stale to start experimenting :-)

It is already on Maven Central. Happy New Year! Happy new YOJ! 🎄

@nvamelichev
Copy link
Collaborator

JFYI @lavrukov @estekhin @g-sg-v ;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants