-
Notifications
You must be signed in to change notification settings - Fork 71
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
Can I dynamically register a domain? #875
Comments
Hi, out of curiosity, what is your use case for this? |
@matrei Thank you for your reply! My application scenario is for users to dynamically define domain models and be able to query data, so I need to dynamically compile and generate domains. I have noticed that GormEnhancer. registerEntity (PersistentEntity entity) should meet my requirements, but how should I obtain an instance of GormEnhancer? I have obtained a PersistentEntity through the following code. Is the usage correct?
|
@matrei I have made some progress. Through the following code, I have implemented the registration of Person, which triggers a listener and calls the registration logic
But when I try to use it through the following code, I still get an error message "Unknown entity: Person"
|
I think the main cause of the problem is the Grails has its own |
Thank you for your answer! I tried the method you mentioned, but the error is still the same as before. |
@ifree-zm Could you provide a minimal and runnable example to reproduce the error, so I can test it with my version to find out how to fix it. |
|
@puneetbehl Are there any plans to add this feature? |
@ifree-zm I spent some time researching and found out that the GORM and Hibernate plugin don't support dynamic registration of entities at this time. |
@rainboyan I plan to let users design their own domain models and directly manipulate the data. For example, if a user defines a Person model, I can automatically concatenate the code and compile it (if possible), and then obtain a Person through the code [Person. find { name=='Tom'}]. Therefore, I need to dynamically compile the Person class instead of defining it in the code beforehand. I have tried to find other similar frameworks, but none of them are ideal... |
@ifree-zm Although GORM's Entity seems simple to use, I don't think it's really suitable for users to write and run as a script on the web front end, since anytime there's user input, there's the possibility of error and the need for back-end data validation. It seems that using SQL or HSQL may be able to realize some data query and export functions, sorry, I don't know the specific needs of your system, and can't give a more definite suggestion. On the other hand, I also don't think Hibernate supports the ability to dynamically configure entities, because if the configuration is changed, it can affect the entire data persistent layer of the framework, causing the system to crash. |
@rainboyan Thank you for your suggestion! Of course, this is just an attempt I want to make. Currently, it seems that this idea is not feasible. Perhaps I can find other better ways. Thank you again! |
with gorm-hibernate5-spring-boot:7.3.1
my code was:
Running the above code will throw an exception:
I found that domain will be registered to STATIC_APIS at project startup. Can I dynamically register Person domain now?
The text was updated successfully, but these errors were encountered: