when I try to add a second field set to an entity it doesn't show in the screens - set

I have six entities and I want to create two field sets from one to two others. One field set is ONE_TO_MANY and I used field set in the ONE side to build the relation and the other is a MANY_TO_MANY and I tried the simplest example from Northwind and that didn't work, and I tried adding --joinTable, --joinColumns, etc. and that didn't work either. Only the ONE_TO_MANY works and only one of those.
Is there a good example with Roo 2.0.0.RC1 that works? or a manual work around?

Remember that Spring Roo just generates and maintains the code that he knows. In this case, you are trying to create a really specific structure, so I recommend you to create it manually. Spring Roo doesnt't have any problem with custom code.
You could check the following repository where exists a lot of examples about relation management managed by Spring Roo or manually.
https://github.com/DISID/disid-proofs
Hope it helps,

Related

adding a constraint to spring entity set field value to one of possible predefined values

good day everyone,
i'm currently working on a spring application for school project, it's about a form generator. anyway i have a question entity which has a field called type, i want that field to be one of 3 different values (radio which is the default, checkbox, or input) but i didn't know how to do this with hibernate annotations or even with the spring constraints annotations so i was hoping someone here has an idea on how to do this.
thanks for your time everyone and hope you have a nice day.

How to create custom SpringBoot Crud Repository Methods to find specific details?

So i have 5 tables as Users,Orders,Products,Ingredients and nutrients,
Each is connected to adjacent table via #ManyToOne annotation.
What i am stuck at is how to find product details of a particular user for a particular order and similarly finding ingredients for a particular product for a particular order for a particular user and similarly for nutrients.
I know i have to declare custom crud methods according to a given syntax and i did so but still the method is not working.
Here is the link to the git repository
https://github.com/Guneet007/API.git
You can use Specification/Querydsl for defining custom criteria. Because we should use more than 3 parameters with AND suffix.
One more issue I have found in your code is that your property name not match with your method findByProductId() it should be findByProduct(Product product). Look same for others too.
https://spring.io/blog/2011/04/26/advanced-spring-data-jpa-specifications-and-querydsl/

Multiple Data Sources with same entity and repo

Currently working on a project where my Spring Boot project needs to
leverage multiple data sources or schema in the same DB server. I have
found several tutorials that teach multiple data source configuration in
spring boot where entity foo exists in DataSource A and bar exists in
DataSource B namely below.,
https://scattercode.co.uk/2016/01/05/multiple-databases-with-spring-boot-
and-spring-data-jpa/
https://scattercode.co.uk/2013/11/18/spring-data-multiple-databases/
https://medium.com/#joeclever/using-multiple-datasources-with-spring-boot-and-spring-data-6430b00c02e7
But my use case is that entities foo and bar are present in multiple schema and I want to use a single entity and repository to access all schema.Data is not replicated in all schema.It is divided among them.
So if I need to search for User John Doe I have to go through Schema 1 and
if I don't find him, move onto the next schema.
I have tried all the above tutorials(even though they don't line up with my
use case) with the hope that I could hack it to get it working just as a
proof of concept.
I have also looked into AbstractRoutingDataSource
(http://fizzylogic.nl/2016/01/24/make-your-spring-boot-application-multi-tenant-aware-in-2-steps/ , http://kimrudolph.de/blog/spring-datasource-routing)
and MultiTentancy but both of these talk about having access to a single
schema at any point in time.
I just need some guidance or link to follow and get this accomplished.
Thanks in advance.
You need to look at AbstractRoutingDataSource and use it.
So if I need to search for User John Doe I have to go through Schema 1 and if I don't find him, move onto the next schema.
Thus you need to search in first schema and if not found, then go on to next schema.
In that example as given in the above link,
CustomerContextHolder.setCustomerType(CustomerType.GOLD);
List<Item> items = catalog.getItems();
if(isEmpty(goldItems)){
CustomerContextHolder.setCustomerType(CustomerType.SILVER);
items = catalog.getItems();
}
More details can be found in another qn here
Managed to resolve the issue by using https://github.com/wmeints/spring-multi-tenant-demo.
Thanks #surya for your recommendation.

spring JPA - delete by marking the entry

I would like to know if Spring or JPA has something implemented to take care of this problem.
In Entity Framework there is something similar with this.
When I want to delete an object, I don't want to remove it from the database. Instead I want to mark it as deleted by using a datetime field.

Changing the model's attributes - adding or removing attributes

I am working on a MVC3 code first web application and after I showed the first version to my bosses, they suggested they will need a 'spare' (spare like in something that's not yet defined and we will use it just in case we will need it) attribute in the Employee model.
My intention is to find a way to give them the ability to add as many attributes to the models as they will need. Obviously I don't want them to get their hands on the code and modify it, then deploy it again (I know I didn't mention about the database, that will be another problem). I want a solution that has the ability to add new attributes 'on the fly'.
Do any of you had similar requests and if you had what solution did you find/implement?
I haven't had such a request, but I can imagine a way to get what you want.
I assume you use the Entity Framework, because of your tag.
Let's say we have a class Employee that we want to be extendable. We can give this class a dictionary of strings where the key-type is string, too. Then you can easily add more properties to every employee.
For saving this structure to the database you would need two tables. One that holds the employees and one that holds the properties. Where the properties-table has a foreign-key targeting the employee-table.
Or as suggested in this Q&A (EF Code First - Map Dictionary or custom type as an nvarchar): you can save the contents of the dictionary as XML in one column of the employee table.
This is only one suggestion and it would be nice to know how you solved this.

Resources