I want to know if it is possible to have Many to many relationships in service.xml in liferay 7.1.
I have my first entity : Service, that is linked to one or many "Zone" entity. So is it possible to do this in service.xml or i must create a relationship table (but not optimized for search and filter) ?
Thanks for your answers
Regards
Related
I need to define an one-to-many relationship between my custom entity and a Liferay default entity DDMFormInstance. So one MyCustomEntity could have many DDMFormInstance's. How can I do it?
you can define collection style columns; furthermore you will need a mapping-table between MyCustomEntity and DDMFormInstance and also remember that service-builder is not an ORM tool, primarily. so there will be a time when out-of-the-box functionalities will end.
<column entity="User" mapping-table="Users_Groups" name="users" type="Collection" />
see more in https://github.com/liferay/liferay-portal/blob/master/portal-impl/src/com/liferay/portal/service.xml
André's answer works by repurposing a many-to-many relationship as a one-to-many relationship. The challenge here is that DDMFormInstance is an out of the box Liferay entity, you cannot add a foreign key to it for the one-to-many relationship. André's answer is the easiest solution. You define a many-to-many relationship in the service.xml using mapping-table, then make it behave as one-to-many relationship in your MyCustomEntityLocalServiceImpl class.
I've just started using Jhipster for a simple project with a very simple datamodel (so far).
I have a question regarding the generated code for the one-to-many relationship:
Is it possible to generate with List instead of a Set, so I can have my child-items ordered?
If no, what is the best solution to solve my problem? I see 2 ways:
Change the generated code manually to use a List and then use liquibase (mvn liquibase:diff) to update my database ?
Have an attribute on the child-item to handle the order ?
What is the best way to handle the "problem" ?
Best regards
Martin Elkkjær
You can use the Spring #OrderBy annotation to sort your sets by the child entity. See http://www.objectdb.com/api/java/jpa/OrderBy
#Entity
public class Person {
...
#OrderBy("zipcode.zip, zipcode.plusFour")
public Set<Address> getResidences() {...};
...
}
I'd also recommend the following blog that explains how Sets/Lists differ for Hibernate and JPA: https://vladmihalcea.com/hibernate-facts-favoring-sets-vs-bags/ (where I found the answer originally)
I need to create my own entities using the JHipster using the command "yo jhipster:entity myEntity" that have many-to-one relationship with the User entity that comes by default in JHipster.
I have tried unsuccessfully to create in the wizard a relationship with the entity "user" and the field "login" but it is not working.
What is the good way to do this with JHipster? Or do I have to create the entity without JHipster tool (but I need the CRUD!).
Thanks,
Yann
Just an update - jhipster 2.5.0 was released a few days ago adding support for this. Created this answer since the formatting in comments make i pretty hard to read.
When creating a relation for your entity simply answer the questions like this
? Do you want to add a relationship to another entity? Yes
? What is the name of the other entity? user
? What is the name of the relationship? owner
? What is the type of the relationship? many-to-one
? When you display this relationship with AngularJS, which field from 'user' do you want to use? login
Possible values on how to display the relation could be: id, login, first_name, last_name, email
See https://jhipster.github.io/2015/03/01/jhipster-release-2.5.0.html for moreinformation
Just to add to the correct answer by #stoffer, if you're using the jdl it will look like:
relationship ManyToOne {
Owner{user(email)} to User{owner(name)}
}
at a good sample in an official document is say :
entity Blog {
name String required minlength(3),
handle String required minlength(2)
}
relationship ManyToOne {
Blog{user(login)} to User
}
jdl-samples/blog.jh
If you are using the 1.x version, this wasn't made to work, so basically you should do it by hand, without the generator (but it is definitely doable).
For the 2.x version, we have refactored the User object to have an ID field -> this should make this a lot easier, but as this is not released yet, we don't have a feedback at the moment.
I have come into this issue and solved it by using a simple one-to-one relationship first that will extend the user entity, because it is simple and manageable easily and can make the extended entity be the owner of the relationship, then you can create the many-to-one relationship with your entity, like this example:
entity MyEntity {
MyField Type
...
}
entity ApplicationUser {
additionalField Type
...
}
relationship OneToOne {
ApplicationUser{internalUser} to User
}
relationship ManyToOne {
MyEntity{appUser} to ApplicationUser{myEntities}
}
For more details and approach refer to this jHipster page.
I am really new to MS Dynamics CRM .. and am stuck with understanding the Relationship and Mapping section.
I want to map the "city" field from Account entity to a "city" field in my custom entity "Custom".
For that I navigate to Account entity settings and create a 1:N relationship with related entity as "Custom" and then map the two fields.
Just like how all related data from "Lead" entity gets transferred to "Opportunities" after "Qualify", I want my custom "city" field to be filled with "city" from "Account" after i create a new account record.
This has something to do with workflows right?
Please correct me if I am wrong anywhere.
It sounds like you want to create a N:1 relationship on your Custom entity which points to the Account entity. If you are not looking for a lookup field, or if the entities are otherwise already related, then the “Mappings” feature of the relationship may be worth looking into. Keep in mind that this type of mapping only works when you are creating the “child” record from the “parent” record (with the parent form open). If you create the record “stand-alone” it won’t auto create the mapping. You can use workflows, however they run asynchronously and you may not see the result right away (which can confuse end users). Aside from that your options are JavaScript (not 100% reliable) or a custom code a Plugin.
In the book .NET Domain-Driven Design with C# from Tim McCarthy there's an example of a link table (two foreign keys + one boolean column) that gets it's own class in the domain. Is this common?
The example is a Contact table and a Project table. The link table is a ProjectContact. What are the pros and cons of using a class ProjectContact instead of having a List of Contacts property in the Project class and a List of Projects property in the Contact class?
I must say that having a ProjectContact class makes it easy to persist a new link between a Project and a Contact... but it seems overkill to me.
Pragmatically spoken (I'm not a DDD expert), I would say that a link table shouldn't pop up in the domain unless it is an entity on it's own (i.e. you need to attach behaviour to it, or it has properties other than the foreign keys).