I need to implement an entity class with an attribute of a collection of enum data. I can't find any related JDL document on the subject. Is it something doable with JDL or do I need to change the generated code as the following afterward?
#ElementCollection(targetClass = MyEnum.class)
#CollectionTable
#Enumerated(EnumType.STRING)
Collection<MyEnum> myEnums;
Related
I would like to create DTO to shape data from a server H2 and merge data from two or three entities on JHipster.
I never used DTO. Do you know where I can find the way to do this?
Thanks!
It's very simple, you can create one manually by defining a simple class with only getters and setters and then you create a Mapper class that will fill the object from the entities. You can see an example in your JHipster project by looking at UserMapper class.
Alternatively, JHipster uses MapStruct to generate them when you select DTO option but frankly it's simpler to code it manually.
Let's say I have an entity Book
I want Jhipster to generate a Books Entity something like
class Books{
List<Book> books;
}
And Generate corresponding rest controllers like
Books saveAllBooks(Books books)
Books updateAllBooks(Books books)
There's no need to create a Books entity if it contains only a list of Book entities, you could just add manually the list methods to generated REST controllerBookResource.java as you don't need any additional repository.
But if Books has other fields that you want to persist in database, you could generate 2 entities with one-to-many relationship. I wouldn't recommend using plural as it could probably conflict with other generated code.
entity Book{
title String required
}
entity BookBatch{
name String required
}
// RELATIONSHIPS:
relationship ManyToOne {
Book to BookBatch
}
I was thinking about how to create a Proposal object like this in JHipster: so a User can create a Proposal and other users can vote for it.
entity Proposal {
proposalText String minlength(2) maxlength(100) required
proposalVotes Integer
}
entity Vote {
numberOfPoints Integer
}
relationship ManyToOne {
Vote{proposal(id) required} to Proposal{vote}
Proposal{user(id) required} to User{proposal}
Vote{user(id) required} to User{vote}
}
In Spring I would create that #Transient proposalVotes Integer and the Controller would go and find all the Votes that a Proposal has and add them together to get to the result to be sent to the frontend. That property would not be stored in the database.
If I use JHipster and I add a proposalVotes property, the result would be saved in the database and could be changed in the dialogs(... and I do not like the result), so my question is:
What is the best practice in JHipster when you need a property that is calculated everytime his object is called?
Think of the number of comments in a Blog with Posts, if it is more familiar.
Where do you calculate the result: I would do it in the ProposalResource, but I’m not sure and I haven’t seen any use case like this in the examples, but it looks like a common case.
Thanks a lot
PD: If there is any example in Github, that could be great!
Actually if you are generating entities using JDL(Jhipster domain language) then you wont get any option to make field Transient as JDL is database design mechanism and Transient fields are not going to be placed in DB.
Solution is that after importing JDL to our app you can add Transient fields in your entity class.
Is there a bulit-in way to obtain an entity name from the class object of an NSManagedObjectSubclass? I know that this can be readily determined from an instance of a subclass, but I want to ask the class itself. I can write a class function, but I would rather do this introspectively.
You can do it now by executing NSManagedObject.entity().name where NSManagedObject() is your subclass.
Check out mogenerator if you haven't already.
http://raptureinvenice.com/getting-started-with-mogenerator/
It adds a lot of missing features to core data. In particular it keeps you from having to regenerate your entity classes.
You could iterate thru the key values of the entities in the context:
[managedObjectContext registeredObjects];
When handling the Selected event of a EntityDataSource, the Results property of the EntityDataSourceSelectedEventArgs returns an ObjectView collection of my entities. I'm not sure what this class is. This link to the Namepace doesn't mention the class.
Is there any documentation on this System.Data.Objects.ObjectView collection class? How would I convert an ObjectView<T> to a List<T>? Perhaps it's as simple as enumerating the collection and adding the items to a new List<T>, but some information about the class would be useful.
The ObjectView class is internal and therefore you cannot find it on MSDN. The important bit of information is that it implements IBindingListInterface