Page 1 of 1

Adding data in new custom entity

Posted: Sun Jul 31, 2016 3:06 am
by ajit
Hello,
I want to add new controller,service,domain(entity),dao for rest api in site module. There is not any tutorial in documentation for the issue while adding data tutorial showing coming soon.
My requirement is that i need complete flow from using REST Api from controller to persisting entity into my custom table.
Is there any link or reference that suggest how to write custom controller,services,entity,dtos and dao And register those daos and entities to persistence unit i.e blpu.
i am trying to register these entities in core modules persistence-core.xml and my entities in site module since it throwing an exception that is blpu class or package not found though it is already present in core.jar file.
So,please provide any reference link or documentation for this issue.

Re: Adding data in new custom entity

Posted: Tue Jul 25, 2017 2:41 pm
by phillipuniverse
Not sure where you're adding a blPU class; this is a String reference to a persistence unit.

To add a new API endpoint, these are automatically component scanned within com.mycompany.api. Simply add a class into that package (or sub-package) annoted with @Controller or @RestController.

To create a new entity, see https://www.broadleafcommerce.com/docs/ ... new-entity

In order to save/query for this entity, you just need to inject the blPU EntityManager into one of your Spring components. Example:

Code: Select all

@Service
public class MyCustomService {
    @PersistenceContext(unitName="blPU")
    protected EntityManager em;
   
    public MyEntity save(MyEntity entityToSave) {
        em.merge(entityToSave);
    }
}


The Broadleaf forums are being retired as a readonly archive of questions. For active discussions and questions, check out the broadleaf-commerce tag on Stack Overflow which is actively monitored by the Broadleaf team.